Reputation: 3266
I'm having trouble configuring log4net to work the way I want. I have a class library Library.dll that is used both by my application Mine.exe and a third party aplication Other.exe. I have another class library Util.dll that is used by both Mine.exe and Library.dll.
Mine.exe and Other.exe are run in parallel and I want the two instances of Library.dll to use the same logfile. It should also be separate from the logfile of Mine.exe. Util.dll should log to Library.dll logfile when called from Library.dll, and the Mine.exe logfile when called from Mine.exe.
Edit: I guess that was a bit hard to follow, this is how I want i to work:
Mine.exe logs to Mine.log
Other.exe doesn't log anything (third party application)
Mine.exe -> Library.dll logs to C:\Library.log
Other.exe -> Library.dll logs to C:\Library.log
Mine.exe -> Util.dll logs to Mine.log
Mine.exe -> Library.dll -> Util.dll logs to C:\Library.log
Other.exe -> Library.dll -> Util.dll logs to C:\Library.log
Other.exe doesn't call Util.dll directly.
First I tried loading a custom log4net configuration in Library.dll, using:
log4net.Config.XmlConfigurator.Configure(new FileInfo("Library.log4net.config"));
But that resulted in Mine.exe also logging to the Library.dll logfile.
I then tried adding the following assembly attribute in Library.dll:
[assembly: log4net.Config.Repository("Library")]
That kept the logs separate, but then Util.dll logged to the Mine.exe logfile even when called from Library.dll. I guess I could use Repository("Util") in Util.dll, AliasReposity("Util", "Library") in Library.dll and AliasReposity("Util", "Mine") in Mine.exe but I actually have many class libraries in the project and would rather not go down that route.
Any ideas on how to get this working?
/Andreas
Upvotes: 1
Views: 3236
Reputation: 4988
I would not share log files to be honest. There are all sorts of threading problems which you may encounter if you log to a file from two processes. Typically one log4net instance will just not be able to log if the other one is, so it will cause log entries to go missing. Also if they are in the same log file, you need to chuck the process name in the log formatter so you know the source. Sounds complicated. By convention, I usually do the following:
You get two files for two processes but this is easier to manage. You can get log file watchers which can display both logs together (although I tend not to use that approach) such as: http://tailforwin32.sourceforge.net/
Upvotes: 1