开发者

log4net print DateTime/calling class/function on each line

开发者 https://www.devze.com 2023-03-23 22:41 出处:网络
I开发者_如何学运维s there any way using log4net to automatically write date/time and class name/function name to the start of each logged line?In the log4net configuration file modify Appender section

I开发者_如何学运维s there any way using log4net to automatically write date/time and class name/function name to the start of each logged line?


In the log4net configuration file modify Appender section by adding a PatternLayout with custom format. Following pattern will output DateTime ClassName.MethodName

 <appender name="DebugOut"
             type="log4net.Appender.OutputDebugStringAppender">
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date{MM/dd/yy HH:mm} %C{1}.%M" />
     </layout>
   </appender>

You can output fully qualified name of class by changing %C{1} to %C

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号