A much simpler way to capture log4net's internal debug messages is to add this snippet of code to the <configuration> node of your app.config or web.config:
<!-- taken from DotNet.Commons.Logging.Impl.SimplerLogger.cs --> <system.diagnostics> <trace> <listeners> <add name="textWriterTraceListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\\log4net.txt" /> </listeners> </trace> </system.diagnostics> --- Ron Grabowski <[EMAIL PROTECTED]> wrote: > If you download and install this free program: > > http://www.sysinternals.com/ntw2k/freeware/debugview.shtml > > And setup log4net to run in Debug mode: > > <appSettings> > <add key="log4net.Internal.Debug" value="true" /> > </appSettings> > > You should be able to see your Appenders being initialized and/or the > exceptions that are caused by incorrectly configured Appenders. > > This is how I log that information to a file in my Asp.Net > application: > > if (log4netIsInDebugMode() == true) > { > // if log4net is in debug mode (useful for discovering why appenders > are not working), it will > // print out internal messages and errors to the System.Console and > to > System.Diagnostics.Trace; > // the code below will capture log4net output and attempt to write > it > to a known writeable > // directory; > string physicalPathLogFile = > Path.Combine(System.Web.HttpRuntime.AppDomainAppPath, > LOG4NET_LOG_FILE); > > try > { > FileStream fileStream = new FileStream(physicalPathLogFile, > FileMode.Create, FileAccess.Write ); > if (fileStream != null && fileStream.CanWrite) > { > // this doesn't affect Trace.axd becuase Trace.axd is > from > System.Web.TraceContext > // System.Diagnostics.Trace.Listeners.Clear(); > System.Diagnostics.Trace.Listeners.Add(new > TextWriterTraceListener(fileStream)); > } > } > catch(SystemException ex) > { > // System.UnauthorizedAccessException - The exception that is > thrown > when the operating system denies access because of an I/O error or a > specific type of security error. > > // log the message to a location that was the cause for the > exception > ??? > System.Diagnostics.Trace.Write("log4net", "Unable to create > log4net > logger at [" + physicalPathLogFile + "]. Exception: " + > ex.ToString()); > } > } > > log4net.Config.DOMConfigurator.Configure(); > > // make sure the complete log4net startup log appears > System.Diagnostics.Trace.Flush(); > > - Ron
