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

--- "Collier, Mike" <[EMAIL PROTECTED]> wrote:

> How would I use the ErrorHandler property for an appender?  For
> example,
> let's assume I'm using the ADONetAppender and for some reason it
> fails
> (i.e. unable to connect to the database server).  I would like to not
> loose the message.  I was thinking that I could use the ErrorHandler
> property to define another appender to use in this case.  However,
> I'm
> not sure how to do this.  Does anybody have any examples or ideas on
> how
> this might be accomplished.
> 
> Thanks!
> 
>  
> 
> 
>       
> 

Reply via email to