logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wolfgang Trog" <wolfg...@wollinet.com>
Subject RE: Defer file creation
Date Mon, 03 Aug 2009 06:43:56 GMT
Hi Ross,

 

thx for the suggestion. I can't defer the logger configuration, because I
need basic logging from the beginning. I could probably use a separate log
file for each job, but that seems a bit awkward. I think I'll stick to the
"write my own appender" approach for the moment.

 

Thx,

Wolfgang

 

 

From: Ross Hinkley [mailto:rosshinkley@gmail.com] 
Sent: Freitag, 31. Juli 2009 18:02
To: Log4NET User
Subject: Re: Defer file creation

 

Off the top of my head: doesn't the logfile only get generated if the logger
is configured?  Rather than deferring the log file getting created, couldn't
you defer execution of the configurator?

You could use a getter to run the configurator, like the following:

private static ILog _log = LogManager.GetLogger(typeof(Program));
public static ILog log
{
    get
    {
        if(!log4net.LogManager.GetRepository().Configured)
            log4net.Config.XmlConfigurator.Configure(new
FileInfo(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));
        return _log;
    }
}

This way, your logger will only get configured (and the file subsequently
made) if something is logged.

Is it a hack?  Absolutely.  But it's the quickest way I could think of to
answer your question. :)

-Ross

On Fri, Jul 31, 2009 at 10:23 AM, Wolfgang Trog <wolfgang@wollinet.com>
wrote:

For now, I  tried a quick hack and modified FileAppender and it's now
working like I want:

 

override public void ActivateOptions()

        {

            .

 

            if ( m_fileName != null )

            {

                //SafeOpenFile( m_fileName, m_appendToFile );

            }

            else

            {

                LogLog.Warn( "FileAppender: File option not set for appender
[" + Name + "]." );

                LogLog.Warn( "FileAppender: Are you using FileAppender
instead of ConsoleAppender?" );

            }

        }

 

I would prefer a solution, where I don't have to use my own appender, but at
least I have a workaround.

 

Regards,
Wolfgang

 

 

From: Wolfgang Trog [mailto:wolfgang@wollinet.com] 
Sent: Freitag, 31. Juli 2009 17:15
To: 'Log4NET User'


Subject: RE: Defer file creation

 

I want to create protocols for jobs that can be executed in our application,
preferably one file per job and execution. But I don't want a file, if the
job is not executed. The jobs are only executed once a month for example. 

 

Thx for the quick response !

 

Wolfgang

 

 

From: Karim Bourouba [mailto:karym6@hotmail.com] 

Sent: Freitag, 31. Juli 2009 17:06

To: log4net-user@logging.apache.org

Subject: RE: Defer file creation

 


Hi There, 

  

I dont think I have an answer to your question just now - but can I ask why
you would prefer to defer creating the log file?



  

  _____  

From: wolfgang@wollinet.com
To: log4net-user@logging.apache.org
Subject: Defer file creation
Date: Fri, 31 Jul 2009 16:15:28 +0200

Hi Everbody,

 

I'm looking for a way to defer the creation of the log file until the first
entry is logged. I want to use log4net for writing protocols for jobs that
can be executed in my application. With my current configuration the file is
created during startup which makes no sense if the job doesn't run.  

 

My current configuration:

 

      <appender name="." type="log4net.Appender.RollingFileAppender">

        <file value="....." />

        <appendToFile value="false" />

        <rollingStyle value="Date" />

        <datePattern value="yyyy_MM_dd.\tx\t" />

        <staticLogFileName value="false" />

        <threshold value="INFO" />

        <layout type="log4net.Layout.PatternLayout">

          <conversionPattern value="%date;%level;%m%n" />

        </layout>

      </appender>

 

One possibility seems to be to generate the appender programmatically, but
then I lose a lot of flexibility. Another one is writing my own appender (or
subclassing an existing one). Is there another way ?

 

Any help is appreciated,

Wolfgang

 

 

  _____  

Share your memories online with anyone you want. Learn
<http://clk.atdmt.com/UKM/go/134665338/direct/01/>  more.

 


Mime
View raw message