My question is similar to this one, but with a somewhat simpler context. In my case I have a single application which may be run twice (at most) simultaneously with different command line parameters, so each instance knows its context.
The app.config file defines a log4net section to configure logging. Here it is:
<log4net xsi:noNamespaceSchemaLocation="http://csharptest.net/downloads/schema/log4net.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<appender name="MainAppender" type="log4net.Appender.FileAppender">
<file value="${TMP}\NCAgent.log" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<appender name="DebugAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="ERROR" />
<appender-ref ref="MainAppender" />
<level value="INFO"/>
<appender-ref ref="DebugAppender"/>
</root>
</log4net>
And, of course, we have a problem that two application instances may log to the same log file, so at runtime one of the instances (the choice is well defined and unambiguous) loads the log4net XmlElement, changes there the name of the log file and configures log4net using the XmlConfigurator.Configure(XmlElement) overload.
I do not like our approach and feel that there should be a better solution. Any ideas?
Thanks.