Adrian,
        You can check to see whether the current repository has been
configured with:

log4net.LogManager.GetRepository().Configured

This isn't ideal, as there are many cases where the logger repository is
configured but wont do what you expect. For instance if the path you are
trying to put the log file into does not exist the configuration will
apparently succeed, but you won't get any logs. Similarly with the case
where the log file already exists but is locked by another process. The
rationale behind this is that (potentially) temporary error conditions
such as these may clear in time and so will not stop logging, as the
appenders will keep trying to operate.

It may be better to use Configure rather than ConfigureAndWatch as the
later could cause the repository to be reconfigured at any time the config
file is changed, which could cause logging to stop working as you expect
mid process. If the config file is not valid XML no changes will occur,
but if it is then the repository will be reconfigured on the fly, which
can be useful in many circumstances, but makes checking the Configured flag
at startup rather redundant.

                Niall Daley

On Wed, 16 Mar 2005, Adrian Walls wrote:

> Niall,
>
> We wanted to use log4net in an application we are developing.  I have
> previously used log4j with no issues whatsoever but this causes us a big
> problem.  This is due to the fact that we cannot determine if logging is
> actually taking place or not.  We were hoping that we could catch this
> as an exception to the event log to indicate that there is a problem
> with the logging.  Otherwise we have no indication that there is a
> problem other than constantly monitoring the log files for activity.
>
> It would be nice even if this returned a return code to indicate if it
> was successful or not.  Least that way we would know logging is active,
> otherwise we could log to another source.
>
> Regards,
> Adrian.
>
>
>
> Niall Daley wrote:
>
> >Adrian,
> >     ConfigureAndWatch does not throw an exception if there is an error
> >in the config file, as this could have unforeseen effects on the
> >application using it. Currently there is no simple way to determine
> >whether log4net configuration has succeeded, but there is a bug raised
> >(http://issues.apache.org/jira/browse/LOG4NET-2) regarding this.
> >
> >                     Niall Daley
> >
> >On Wed, 16 Mar 2005, Adrian Walls wrote:
> >
> >
> >
> >>Hi,
> >>
> >>I am using the log4net 1.2 framework in my application.  I am using the
> >>DOMConfigurator.ConfigureAndWatch(FileInfo) to read and monitor an
> >>external configuration file.  See code below which I us to start my logger.
> >>
> >>   Private Sub startLogger()
> >>        Dim sr
> >>        Try
> >>            'Start Application Logger
> >>            DOMConfigurator.ConfigureAndWatch(log4netConfig)
> >>        Catch e As Exception
> >>            sr = New StreamWriter("C:\Log4NetErrorStartLogger.log")
> >>            sr.WriteLine("Exception: " + e.Message())
> >>            sr.Close()
> >>        End Try
> >>
> >>However if there is an issue with the config file (if for example I
> >>remove a brace from one of the XML tags to throw an parsing exception)
> >>then log4net will simply not log anything.  But it does not throw an
> >>exception to indicate that there is something wrong,  should it not
> >>catch exceptions thrown by the DOMConfigurator and write it to the
> >>stream writer log file as configured as above.
> >>
> >>Or is there some issue with my code above.  Any help which can shed some
> >>light on this issue will be greatly appriciated.
> >>
> >>Regards,
> >>Adrian
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
>

-- 
Niall Daley
Log4net Dev

Reply via email to