Thanks for the code snippet, Barry!

So I assume I take the existing FileAppender <appender> configuration out of
my configuration file.  A small wrinkle though: I've got a TraceAppender
defined in the config file right now - I can leave that as is and both
appenders will still work?  Or does the
log4net.Config.BasicConfigurator.Configure bypass any config file?

Thanks again.
Corey.

-----Original Message-----
From: Barry Burton [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 01 June, 2004 10:12
To: Log4NET User
Subject: Re: Changing FileAppender log file at runtime

Here is the code to do exactly what you want:

Hierarchy hierarchy;

if((hierarchy = (Hierarchy)
LogManager.GetLoggerRepository()) != null ) {
    FileAppender  fileAppender          = new FileAppender();

    PatternLayout patternLayout         = new
PatternLayout();

    string                logFile       = string.Format(
@"{0}\myLogFile.log", myLogDir );
    string                logThreshold  = "DEBUG"; // whatever you
want here...

    patternLayout.Header                = "[Begin]\r\n";
    patternLayout.Footer                = "[End]\r\n\r\n";
    patternLayout.ConversionPattern     = "%d [%t] %-5p
%c - %m%n";

    fileAppender.Name                   = config.myAppenderName;
    fileAppender.File                   = logFile;
    fileAppender.AppendToFile           = true;
    fileAppender.ImmediateFlush         = true; // IMPORTANT
    fileAppender.Layout                 = patternLayout;
    fileAppender.Threshold              = Level.DEBUG;

    fileAppender.ActivateOptions();

    log4net.Config.BasicConfigurator.Configure(
fileAppender );
}





--- "Wirun, Corey" <[EMAIL PROTECTED]> wrote:
> Hi All,
> 
> Is it possible with 1.2.0 beta8 (.Net Framework 1.1) to change the 
> FileAppender log file at runtime (versus getting it from my config 
> file and using it from that point on)?
> 
> I've got an ASP.NET application calling my assembly on the backend and 
> I want to generate log files (when enabled) with a name based on 
> something from the session information.
> 
> Thanks in Advance!
> Corey.
> 
> -----
> Corey MJ Wirun, B.Sc.
> AspenTech Canada, Ltd. Calgary Alberta home office: 403 720-3699 fax: 
> 403 720-3699 (shared line, voice call ahead!) "Anything will fly with 
> 10KLbs of thrust.  Landing?
> That's a different
> story." - power does not mean capability.
>  
> 



        
                
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

Reply via email to