0
如何在使用UseNLog()实施的Topshelf应用程序中使用custom variables and layout?我想发送类似于ID号的内容,以便可以使用$ {mdc:item = MyValue}语法将其放入日志中。Topshelf和NLog - 使用自定义变量
如何在使用UseNLog()实施的Topshelf应用程序中使用custom variables and layout?我想发送类似于ID号的内容,以便可以使用$ {mdc:item = MyValue}语法将其放入日志中。Topshelf和NLog - 使用自定义变量
可以使用MappedDiagnosticsLogicalContext NLOG像这样:
NLog.MappedDiagnosticsLogicalContext.Set("PropertyName", PropertyValue);
设置的第一个参数是表示属性名的字符串。第二个参数将一个对象作为其值。
当然你需要用'$ {mdc:MyValue}'而不是'$ {event-properties}'来读取它们。请参阅https://github.com/nlog/nlog/wiki/MDC-Layout-Renderer – Julian