can I pass a custom property to NLOG and output to file?

前端 未结 4 964
囚心锁ツ
囚心锁ツ 2021-02-06 05:43

EDIT 4: \"From\" seems to be a reserved word in NLog. Changing it \"FromID\" worked. this is an awesome way to pass variables to NLog and still keep your code clean !!!! TH

4条回答
  •  悲&欢浪女
    2021-02-06 06:17

    Use MDLC Layout Renderer

    MappedDiagnosticsLogicalContext.Set("PropertyName", "PropertyValue"); MappedDiagnosticsLogicalContext.Set("PropertyName2", "AnotherPropertyValue");

    In your nlog config:

    ${mdlc:item=PropertyName} ${mdlc:item=PropertyName2}

    https://github.com/NLog/NLog/wiki/MDLC-Layout-Renderer

提交回复
热议问题