Nlog发布到CosmosDB目标

3
我正在使用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发布的任何信息,我只发现了有关配置它的信息,我相信我已经正确地完成了配置。谢谢。
1个回答

4

在我的电脑上可以正常运行。您尝试记录的对象是否与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。 - II Basil II
1
你是否也尝试过使用Azure Cosmos DB模拟器进行本地测试? - ngruson
没有,我会尝试一下。 - II Basil II
1
当我设置模拟器时,我意识到我交换了集合名称和数据库名称。现在它正在工作。 - II Basil II

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接