I have a application which is loading PlugIn-Modules with reflection.
The Application is defining a log4net-log-appender in the app.config like:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs\xxx.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<threshold value="DEBUG" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger{2} - %message%newline" />
</layout>
</appender>
I get the Logger in the code like:
private static readonly ILog log = LogManager.GetLogger(typeof(Indexer));
Now, I am searching a way to declare different Log-Files for each Module (assembly), which is loaded as PlugIn with reflection.
The first problem is, that the modules are using Business-Library-Classes together (they are in a assembly which is used of all modules) which also generates log-entries. This entries should also be inserted in the log-file of the module.
The second problem is, I don’t know the modules at developing-time. So I cannot insert some config in the app.config.
This reveals that it might not be possible in the config file. When you add a new plugin, you can add code to add a new appender for the plugin.
Hers some (code) to get you inspired:
You need to add that it is only from the plugin-assembly you want to log, and maybe omit them from the already configures RollingFileAppender.