views:

29

answers:

1

I want to log some summary lines on domain shutdown, however log4net hooks the AppDomain.CurrentDomain.ProcessExit first and will shutdown the logging before I have a chance to output my message. (And the message is never logged)

So my question is: 1. Is there a way to hook ProcessExit before log4net without playing too much with initialization order? (Certainly without changing the Program class of my application) 2. Does log4net provides any hook which it invokes just before shutdown?

A: 

The logger repositories (accessible with log4net.LogManager.GetAllRepositories()) have a event: ShutdownEvent. This is not useful for you since this event is raised after log4net shut down everything.

Hooking into AppDomain.CurrentDomain.ProcessExit worked quite fine for me. I just need to do that before I initialized log4net. (Not sure if that qualifies as "not playing too much with initialization order".)

Stefan Egli
Yes, the order is certainly the problem. Not only the main assembly initializes the log4net as one of the first things (obviously), but also many dependencies do the same. It simply looks illogical to initialize something which logs to log4net before the log4net itself, and all of this because of the inability to control the order of event delegates. Ah well...
EFraim