gpt4 book ai didi

c# - Nlog 发布到 CosmosDB 目标

转载 作者:行者123 更新时间:2023-11-30 15:52:42 25 4
gpt4 key购买 nike

我正在使用 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 发布的任何信息,我只找到了有关配置它的信息,我相信我做对了

谢谢

最佳答案

在我的电脑上工作。您尝试记录的对象是否与 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"
});

关于c# - Nlog 发布到 CosmosDB 目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53800336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com