tags:

views:

30

answers:

2

In normal separate XML file configuration i place in my root directory my application works just fine with both appenders.

However, I have found an easy and more efficient way to configure from an external file Which allowed me the flexibility of using the same config file for different applications...

Also one more advantage is I dont need to make any modification to the global.asax and assembly.

Here is the code which i added to my web.config

<appSettings>
    <add key="log4net.Config" value="C:\\log\Log4Net.config"/>
</appSettings>

This code is suppose to put the config file in my root directory. And all I needed to do was reference the log4net.dll and start logging.

Even-though my AdoNetAppender is completely working fine and i am seeing the messages instantly in my table. But my fileAppenders arent creating any files neither logging the messages to existing files. Is this way only compatible with database or I'm missing something?

A: 

It's not possible with the standard RollingFileAppender to log into one single file from multiple processes because the appender locks the file to write in it. The log4net FAQ provides a solution for this.

See log4net FAQ

Regards

Philipp G
A: 

You can set the LockingModel of the RollingFileAppender to MinimalLock to force the appender to open and close the file for every logging event. Not exactly efficient, and there is still a possibility that one application will not be able to log if they try to log at the exact same time, but if your logging frequency is low enough it may be sufficient.

A better solution is to use a pattern string for the file name of the appender that includes the application name; that way, different applications can use the same config file, but will write to different log files. In most cases the "%appdomain" variable will work for that purpose (although for web or ClickOnce applications you have to get a little more creative).