user623879
user623879

Reputation: 4142

log4net print DateTime/calling class/function on each line

Is there any way using log4net to automatically write date/time and class name/function name to the start of each logged line?

Upvotes: 4

Views: 1295

Answers (1)

sll
sll

Reputation: 62564

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

Upvotes: 6

Related Questions