tags:

views:

470

answers:

1

Right now, I'm programmatically configuring log4net by creating a RollingFileAppender instance then calling BasicConfigurator.Configure(). This is working great, but I'm trying to create two identical files - one in a timestamped directory that gets created for every run of the app, another in a static location to make it easy for a developer to tail the most current log. (this is only used for running automated tests, so creating a huge pile of directories is not a concern)

Ideally, I'd like the files to be completely identical, but I realize log4net might not make this possible. If they have different logger names, that's fine - as long as I can have one log statement write to both log files.

My current code:

IAppender appender = new RollingFileAppender
{
    ...
}

appender.ActivateOptions();

BasicConfigurator.Configure(appender);
+1  A: 

Although it's perfectly possible to do it completely Programmatically I don't feel like explaining the API here, it's easy enough to lookup.

By far the easiest and most flexiable way would be to configure two appenders read it from the config file. You can force this by calling upon log4net.Config.XmlConfigurator.Configure() and you can even pass in a XmlElement into Configure() if you want to keep it all in code.

olle
Building the XML programmatically then calling XmlConfigurator turned out to be much simpler. Thanks.
Zack Elan