【问题标题】:Nlog Posting to a CosmosDB TargetNlog 发布到 CosmosDB 目标
【发布时间】:2018-12-17 02:09:46
【问题描述】:

我正在使用 Nlog 并尝试将其发布到 CosmosDB(DocumentDB) 目标 使用https://www.nuget.org/packages/Nlog.DocumentDBTarget/

我的配置代码是这样的

  var documentDBTarget = new DocumentDBTarget()
        {
            Name = "logDocument",
            EndPoint = "https://[my endpoint].documents.azure.com:443/",
            AuthorizationKey = "[my auth key]",
            Collection = "[my collection]",
            Database = "[my database]",
            Layout=jsonLayout
        }; 
        config.AddTarget(documentDBTarget);
        config.AddRuleForAllLevels(documentDBTarget);

我已经声明了 jsonLayout,然后我配置了记录器并使用它来开始记录。当我登录到本地文件目标或控制台目标时,这工作正常,但它不适用于 cosmosDB

LogManager.Configuration =config; 
Logger logger = LogManager.GetLogger("Example");          
logger.Info("{object}");

我错过了什么? https://github.com/goto10hq/NLog.DocumentDB?files=1 的文档 我没有找到任何关于使用 Nlog 发帖的信息我只找到了关于配置它的信息,我相信我做对了

谢谢

【问题讨论】:

    标签: c# azure-cosmosdb nlog


    【解决方案1】:

    在我的电脑上工作。您尝试记录的对象是否与 JSON 布局一致?

    var jsonLayout = new JsonLayout()
            {
                Attributes =
                    {
                        new JsonAttribute("name", "${name}"),
                        new JsonAttribute("level", "${level}"),
                        new JsonAttribute("message", "${message}"),
                    }
            };
    …
    
    logger.Info(new
            {
                Name = "SomeName",
                Level = "SomeLevel",
                Message = "HelloWorld"
            });
    

    【讨论】:

    • 是的,这正是我目前正在做的,但仍然没有发布到 cosmos
    • 您是否也尝试过使用 Azure Cosmos DB 模拟器进行本地测试?
    • 没有,我试试看
    • 当我设置模拟器时,我意识到我切换了集合名称和数据库名称。现在它正在工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多