views:

276

answers:

2

We have a set of web services which is also our internal API. They perfectly share one common web.config file.

Is there a way to somehow make log4net create one log for the whole site, for all of them? And have common error handler? The problem I think they are all separate virtual directories, separate applications...?

But again...they share the same web.config file and it works fine...can they somehow share global.asax or whatever? Can't get it to work...

Thanks for any help.

A: 

Are they all inside the same project? Are they ASMX Services? If so and you can put them in the same virtual directory there shouldn't be a problem.

Mitchel Sellers
@Mitchel Sellers: Yes, they are all ASMX's but they are all in different projects. Merging them is one of the solutions but it will take way more time...
badbadboy
+1  A: 

From log4net's FAQ:

How do I get multiple process to log to the same file?

By default the FileAppender holds an exclusive write lock on the log file while it is logging. This prevents other processes from writing to the file. The FileAppender can be configured to use a different locking model, MinimalLock, that only acquires the write lock while a log is being written. This allows multiple processes to interleave writes to the same file, albeit with a loss in performance. See the FileAppender config examples for an example MinimalLock configuration.

While the MinimalLock model may be used to interleave writes to a single file it may not be the optimal solution, especially when logging from multiple machines. Alternatively you may have one or more processes log to RemotingAppenders. Using the RemoteLoggingServerPlugin (or IRemoteLoggingSink) a process can receive all the events and log them to a single log file.

Without additional configuration, log4net puts an exclusive lock on the file. Using their MinimalLock setting, you can "hopefully" get shared logging. In other words, your mileage may vary.

As a suggested alternative strategy, since you've got an internal API with web services, consider a web service method that implements a single private static logger in the background and adds entries to the log. You could call the logging web method (asynchronously if performance is critical) from your other web methods where you want to implement logging.

jro