Log4net traceappender doesn't write anything

I would like to redirect all log4net protocols to System.Diagnostics Trace classes. My understanding of what I should do is point log4net to system.diagnostics.traceappender, then I configure system.diagnostics. Here are the important parts in my web.config:

<log4net> <appender name="trace" type="log4net.Appender.TraceAppender, log4net"> <immediateFlush value="true" /> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" /> </layout> </appender> <root> <priority value="DEBUG"/> <appender-ref ref="trace"/> </root> </log4net> <system.diagnostics> <sources> <source name="Console" switchName="DefaultSwitch"> <listeners> <add type="System.Diagnostics.DefaultTraceListener" name="Default"> <filter type="" /> </add> </listeners> </source> <source name="Metabase" switchName="MetabaseSwitch"> <listeners> <add name="MetabaseListener" /> <remove name="Default" /> </listeners> </source> <source name="TextFile" switchName="TextFileSwitch"> <listeners> <add name="TextFileListener" /> <remove name="Default" /> </listeners> </source> </sources> <sharedListeners> <!--<add name="ConsoleListener" type="XXX.Manufacturing.Utilities.Diagnostics.ColorConsoleTraceListener,XXX.Manufacturing.Utilities" />--> <add name ="TextFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextFile.log" /> <add name="MetabaseListener" type="XXX.Manufacturing.Utilities.Diagnostics.MetabaseTraceListener,XXX.Metabase.Proxies" /> </sharedListeners> <switches> <add name="MetabaseSwitch" value="Information" /> <add name="DefaultSwitch" value="Verbose" /> <add name="TextFileSwitch" value="Verbose"/> </switches> </system.diagnostics> 

Did I miss an important step related to this? If I go around log4net and just create a new tracing resource, it will go to my sources.

+6
log4net system.diagnostics
source share
2 answers

I added an XmlConfigurator.Configure () call and turned on internal logging. I saw that log4net was logging, but nothing got to the tracking system. After playing with my app.config for a while, I found a configuration that worked, the most noticeable changes seemed to interrupt the sources in my System.Diagnostics configuration and make sure the log4net level attribute was set. Working configuration sections:

  <log4net> <appender name="trace" type="log4net.Appender.TraceAppender, log4net"> <immediateFlush value="true" /> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" /> </layout> </appender> <root> <level value="ALL"/> <appender-ref ref="trace"/> </root> </log4net> <system.diagnostics> <trace autoflush="true" > <listeners> <add name="TextFileListener" /> <add name="MetabaseListener" /> </listeners> </trace> <sharedListeners> <add name ="TextFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextFile.log" /> <add name="MetabaseListener" type="XXXX.Manufacturing.Utilities.Diagnostics.MetabaseTraceListener, XXXX.Metabase.Proxies" /> </sharedListeners> 

+3
source share

You called the XmlConfigurator.Configure(); method XmlConfigurator.Configure(); ?

If this is not a problem, you can turn on internal debugging (explain here ) or maybe set up a console appender and see if this works.

Edit: I am not familiar with the trace system, but if you configure the trace listener as follows, you should get the output of log4net:

 <system.diagnostics> <trace autoflush="true"> <listeners> <add name="textWriterTraceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\temp\log4net.txt" /> </listeners> </trace> </system.diagnostics> 
+3
source share

All Articles