[英]formatting a custom property in log4net
I have the following conversionPattern for a log4net appender. 我有一个log4net附加程序的以下conversionPattern。 I am setting a custom property in code (a DateTime object), and i'm able to output the property to a log4net log.
我正在代码(DateTime对象)中设置自定义属性,并且可以将属性输出到log4net日志。
<appender name="FilteredLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="${USERPROFILE}\logs\UserConfiguredFilteredLog.txt" />
<param name="AppendToFile" value="true" />
<param name="ImmediateFlush" value="true" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]
" />
<param name="Footer" value="[Footer]
" />
<!-- I don't think I can apply custom formating on the CustomDate property-->
<param name="ConversionPattern" value="%d [%t] %property{LoggerCategory} [UserCustomTime:%property{CustomDate}] %-5p %c %m%n" />
</layout>
</appender>
My question is: How can I format the CustomDate property that I set? 我的问题是:如何格式化设置的CustomDate属性? I've tried adding %d and -d and stuff like that in various combination, but can't figure it out.
我试过以各种组合添加%d和-d以及类似的东西,但无法弄清楚。 I'm not sure if it's possible.
我不确定是否可以。
It seems you are putting the custom property on the log4net.ThreadLogicalContext which is of type DateTime . 似乎您正在将custom属性放在类型为DateTime的log4net.ThreadLogicalContext上。 Why not put it in string format instead of the DateTime type.
为什么不以字符串格式而不是DateTime类型。 This make the output a lot easier as trying to add a layout into your configuration.
尝试将布局添加到配置中时,这使输出变得容易得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.