Sorry, I cannot grasp your requirements. Please try to explain your usecase better in a way that gives the document some kind of structure.
On 23 Oct 2016 12:02 a.m., "Nicholas Duane" <nic...@msn.com> wrote: > Thank you for the suggestions. > > > We are already logging complex objects in many cases. We have the notion > of a compliance event. That's basically a map (IDictionary<string, > object>). We're now adding business events. However, even with these > "complex" events I don't want the map to contain the category, at least not > at event creation time. I see an event as just a collection of > properties. The act of logging it at a certain level or category is what > assigns the severity or category. For example: > > > logger.Warn("this is my warning message"); > > > logger.Error("this is my error message"); > > > logger.Info("this is my info message"); > > > In each of those cases if we assume the event is the message itself, there > is no criticality associated with that event. It's the act of logging that > defines the event's criticality. I want the same to be true for the > category. I believe I have this working fine for our "complex" events > which don't fit into the Level gradient. I expose a LogEvent() method > which logs at the Emergency level as I showed in the code I included in the > previous thread. However, we also need to capture diagnostic events, ones > that are logged via the logging framework's methods: > > > logger.Error(...); > > logger.Warn(...); > > > What I am hoping to do is hook in some of my code and generate one of our > complex events each time the logging framework logs an event and will map > the level to one of our categories. I can imagine that this might be > possible if I somehow wrap a logger, but as I mentioned I don't want the > user to have to call anything special at startup to hook up that wrapping. > I was hoping there would be a way for me to hook myself in via > configuration. I'm ok with giving them a configuration file they need to > use but I don't want them to have to change any existing code them may have. > > > By the way, we did generate a custom log level for our compliance event. > However I'm trying to move away from that as it was point out that our > events don't fit well within the level gradient. So the new code for > logging a compliance event does not use that level. Both the compliance > and business event would be logged at the Emergency level. I would use the > category property to differentiate them. Similar, I guess, to log4j2's > Markers. > > > Thanks, > > Nick > > > ------------------------------ > *From:* Dominik Psenner <dpsen...@gmail.com> > *Sent:* Saturday, October 22, 2016 1:29 PM > *To:* Log4NET User > *Subject:* Re: Injecting properties into LoggingEvent > > > What I am proposing here are a mere ideas that will need further > investigation. I have not tried any of these ideas. You will have to > prioritize these ideas based on your requirements. > > A. Implement an extension class for the ILog interface > B. Implement a custom ILog interface implementation and a LoggerFactory. > C. Define custom loglevels > D. Use thread context properties altogether with custom format layouts > E. Log "complex" classes that hold your category information and find a > way to format them > > There might be more things that you could do.. > > On 22 Oct 2016 5:31 p.m., "Nicholas Duane" <nic...@msn.com> wrote: > >> Is there a way for me to inject properties into a LoggingEvent? I'm >> trying to accomplish this without the user (of log4net) doing anything >> special. The only thing I could think of was wrapping loggers, and while >> I'm not against doing that it would have to be done via configuration as I >> don't want the user to have to do it programmatically. Is there any way >> for me to inject a logger wrapper via configuration? >> >> >> The reason I'm looking to do this is that I would like to set a property >> on the LoggingEvent to use for filtering. This property would be >> determined based on the level property. I could simply use the level >> property for filtering, but I have other events which I generate which are >> all logged at the Emergency level but have a different value for this >> property so for them I'm using this property for filtering. I don't have >> the same issue with these other events because they are logged via an >> extension method I provided on the ILog interface: >> >> >> public static class Logging >> >> { >> >> public static void LogEvent(this ILog logger, Category category, >> IEvent evnt) >> >> { >> >> if ((category != null) && (evnt != null)) >> >> { >> >> evnt.SetCategory(category.Name); >> >> LoggingEvent le = new LoggingEvent(null, >> logger.Logger.Respository, >> >> logger.Logger.Name, Level.Emergency, evnt, null); >> >> le.Properties["category"] = category.Name; >> >> logger.Logger.Log(le); >> >> } >> >> } >> >> } >> >> >> So for instance when a user does the following: >> >> >> logger.Error("this is my error message"); >> >> or >> >> logger.Warn("this is my warning message"); >> >> or >> >> logger.Info("this is my info message"); >> >> >> I would like to set the property "category" on the LoggingEvent to >> "criticalDiagnostic". When they do: >> >> >> logger.Debug("this is my debug message"); >> >> or >> >> logger.Trace("this is my trace message"); >> >> >> I would like to set the property "category" on the LoggingEvent to >> "noncriticalDiagnostic". Any way for me to do that automagically? >> >> I also posted this at: >> >> >> http://stackoverflow.com/questions/40187597/injecting-proper >> ties-into-log4nets-loggingevent >> >> >> Thanks, >> >> Nick >> >