Use log4net's ThreadContext On Sat, Mar 21, 2009 at 5:57 PM, Callum Hibbert <[email protected]>wrote:
> Can someone give me a pointer on how I can get the Event ID populated when > logging to the Event Log via the Logging Facility and log4net? > I understand how to do this if I own all the code but I'm having trouble > seeing an elegant way of passing a value for the Event ID when using the > Logging Facility. If I owned all the code I would have log4net log a > "LoggingEvent" as follows: > > LoggingEvent loggingEvent = new LoggingEvent(_caller, > _log.Logger.Repository, _log.Logger.Name, Level.Info, message, exception); > loggingEvent.Properties["EventID"] = eventId; > _log.Logger.Log(loggingEvent); > > I thought about providing the Logging Facility with a custom factory (which > would provide my own logger) but I'm still bound to the "ILogger" interface > to which I can only really provide messages in text form, no hook for an > Event ID. > > There is the possibility of setting "EventID" property "globally" on > log4net before making the call to ILogger (and resetting after the call) > e.g. > > _log4netLogger.Logger.Repository.Properties["EventID"] = eventId; > > This is likely to leave me with threading/race conditions when two widgets > are logging at the same time. > > Anyone have any ideas for an elegant solution? > > Thanks very much, > > Callum > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
