使用beginScope作为JSOM的nlog格式
使用 ilogger.beginscope
,如何使NLOG将NLOG格式化为JSON?看起来@
符号被忽略,或者只是没有编码以使用开始范围? ref 文档
我已经尝试了所有我可以尝试的组合想一想,它们都导致对象为 toString
'd,而不是转换为JSON。最终结果是数据无法作为“结构化”数据搜索,因为它只是一个字符串。
第一次尝试:
using (_logger.BeginScope(new Dictionary<string, object>
{
["CacheValue"] = value
}))
{
_logger.LogInfo("howdy");
}
seq中的结果:
howdy
CacheValue MyApp.ViewModels.EntityIssueQueueGetModel
第二尝试:
using (_logger.BeginScope(new Dictionary<string, object>
{
["@CacheValue"] = value
}))
{
_logger.LogInfo("howdy");
}
seq中的结果:
howdy
@CacheValue MyApp.ViewModels.EntityIssueQueueGetModel
第三尝试:
using (_logger.BeginScope(new Dictionary<string, object>
{
["{@CacheValue}"] = value
}))
{
_logger.LogInfo("howdy");
}
在SEQ中结果:
howdy
{@CacheValue} MyApp.ViewModels.EntityIssueQueueGetModel
第四尝试:
using (_logger.BeginScope("{@CacheValue}", value))
{
_logger.LogInfo("howdy");
}
seq中的结果:
howdy
@CacheValue MyApp.ViewModels.EntityIssueQueueGetModel
下一个位,但不是我所需要的。这与友好的信息一起打印出JSON。我只希望JSON数据与日志关联以进行查询目的;未作为消息的一部分显示。
工作示例:
_logger.LogInfo("howdy. {@CacheValue}", value);
seq中的结果:
howdy. {"Issues":[],"TotalRecords":0,"Success":true,"TraceId":"00-3b8ef0c2d84714e0c81a07cbb5d50444-8269922e21923478-00","Errors":[]}
CacheValue {
"Issues": [],
"TotalRecords": 0,
"Success": true,
"TraceId": "00-3b8ef0c2d84714e0c81a07cbb5d50444-8269922e21923478-00",
"Errors": []
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
nlog无法识别范围内下文范围内的消息 - 网板词法。
nlog jsonlayout可以格式化范围 - 上下文属性类似:
另请参阅: https://github.com/ nlog/nlog/wiki/jsonlayout
也可以将单个示波器 - 属性属性格式化为JSON,
也可以: https://github.com/nlog/nlog/nlog/nlog/wiki/scopeproperty-layout-renderer
也有可能将整个Scope-nested-stack as Gremat AS格式化为JSON类似:
另请参阅: https://github.com/nlog/nlog/nlog/nlog/nlog/nlog /wiki/scopenested-layout-Renderer
也许可以考虑在
NLog doesn't recognize message-template-syntax for Scope-Context-Properties.
NLog JsonLayout can format Scope-context Properties like this:
See also: https://github.com/NLog/NLog/wiki/JsonLayout
It is also possible to format a single Scope-context Property as Json like this:
See also: https://github.com/NLog/NLog/wiki/ScopeProperty-Layout-Renderer
It is also possible to format the entire Scope-Nested-Stack as Json like this:
See also: https://github.com/NLog/NLog/wiki/ScopeNested-Layout-Renderer
Maybe consider posting your question at https://github.com/datalust/nlog-targets-seq