Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D9B31200BA9 for ; Sun, 23 Oct 2016 15:18:51 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D8367160AFC; Sun, 23 Oct 2016 13:18:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CFD86160AD8 for ; Sun, 23 Oct 2016 15:18:50 +0200 (CEST) Received: (qmail 28288 invoked by uid 500); 23 Oct 2016 13:18:48 -0000 Mailing-List: contact log4net-user-help@logging.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Log4NET User" List-Id: Delivered-To: mailing list log4net-user@logging.apache.org Received: (qmail 28278 invoked by uid 99); 23 Oct 2016 13:18:47 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Oct 2016 13:18:47 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 15F47180E26 for ; Sun, 23 Oct 2016 13:18:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.679 X-Spam-Level: * X-Spam-Status: No, score=1.679 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id f1Q5UVDbFujl for ; Sun, 23 Oct 2016 13:18:44 +0000 (UTC) Received: from mail-it0-f53.google.com (mail-it0-f53.google.com [209.85.214.53]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 9E1A45F3F3 for ; Sun, 23 Oct 2016 13:18:43 +0000 (UTC) Received: by mail-it0-f53.google.com with SMTP id 198so76705436itw.0 for ; Sun, 23 Oct 2016 06:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=LrhcdGcR/iZxmmlCOUF2rmqPsaO0cdGNpUOqTUCooW4=; b=AzPHynAW4AVty/99nty/zqXSv3AYB9Qo6W3+WeqT2mLTNrJnMy3SgmsDVKpNA2YvWa TC+Et66Fl4ObE74YQGgxI75MOR1oyWtcQNb9n5Oy4NYPAWTVhHcJcr3sjACpBpg72zg5 CVULoosl9zUZs/MWode8sei7//AMXxaFy5XNW03e/xOab9S2dtKjWiNgXZ52eC9X7Tbg +CASJQSBlCE8FU0TQfwRm+sbkKvPi8AAeELdbHZuStVxwrr/GH4OY14PJRq33Gyj12wm Ow7a8MYU/PMJ5cgjzQEVRwTvVZ3owmiRnTmtlFMPCErMLIVxDJqQSY395hUOTRfmEK6f lh1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=LrhcdGcR/iZxmmlCOUF2rmqPsaO0cdGNpUOqTUCooW4=; b=mVCjJNFBa8nrBbBbuPbnaSo4/ZiRySug2kV8Mt3kuzqLj3zRr6OviG13QL9s1KO9Gp EVyPhQzFn6S3D+GJP4eFzXdabxUpt1rlSMpG4s8Gvz+b3nSyOFGB5wA0s7iRJvzXNak3 wtnq7IwAv2xFNqwR/mQQ6ZvTpob2eI87wANd4ghqLxGli+GTgrDi0Kj7q+r20EirTCah A88izq0fxVykS7YTNKUpv50T51xf1/ZwPQrZqCTrYWiWQu8ikh8NeGA9lvwxJRi9TYh5 RXyjw4KGK8gLvnmzBUm7otgV6LsTZm3TnAEC6vn0dJwZSap4pPiGl/CwDRfq9/t7mzdZ F5Lw== X-Gm-Message-State: AA6/9RmPpXlpdHUYkxM7h6lnhZN40UIOo3nxegHSSVfEguLpsK4rezm3yrtodVewx0TVe5i+9IsKLo+H9XXaog== X-Received: by 10.202.87.16 with SMTP id l16mr17559668oib.126.1477228706451; Sun, 23 Oct 2016 06:18:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.202.3.130 with HTTP; Sun, 23 Oct 2016 06:18:25 -0700 (PDT) Received: by 10.202.3.130 with HTTP; Sun, 23 Oct 2016 06:18:25 -0700 (PDT) In-Reply-To: References: From: Dominik Psenner Date: Sun, 23 Oct 2016 15:18:25 +0200 Message-ID: Subject: Re: Injecting properties into LoggingEvent To: Log4NET User Content-Type: multipart/alternative; boundary=001a113ad9284cd4cc053f881ca9 archived-at: Sun, 23 Oct 2016 13:18:52 -0000 --001a113ad9284cd4cc053f881ca9 Content-Type: text/plain; charset=UTF-8 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" 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 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 > *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" 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 >> > --001a113ad9284cd4cc053f881ca9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Sorry, I cannot grasp your requirements. Please try to expla= in your usecase better in a way that gives the document some kind of struct= ure.


On 23 Oct 2016 12= :02 a.m., "Nicholas Duane" <= nickdu@msn.com> wrote:

Thank you for the suggestions.


We are already logging complex objects in many cases.=C2=A0 We have the = notion of a compliance event.=C2=A0 That's basically a map (IDictionary= <string, object>).=C2=A0 We're now adding business events.=C2=A0 = However, even with these "complex" events I don't want the ma= p to contain the category, at least not at event creation time.=C2=A0 I see an = event as just a collection of properties.=C2=A0 The act of logging it at a = certain level or category is what assigns the severity or category.=C2=A0 F= or 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, the= re is no criticality associated with that event.=C2=A0 It's the act of = logging that defines the event's criticality.=C2=A0 I want the same to = be true for the category.=C2=A0 I believe I have this working fine for our "complex" events which don't fit into the Level= gradient.=C2=A0 I expose a LogEvent() method which logs at the Emergency l= evel as I showed in the code I included in the previous thread.=C2=A0 Howev= er, 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 ou= r complex events each time the logging framework logs an event and will map= the level to one of our categories.=C2=A0 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 spec= ial at startup to hook up that wrapping.=C2=A0 I was hoping there would be = a way for me to hook myself in via configuration.=C2=A0 I'm ok with giv= ing 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.= =C2=A0 However I'm trying to move away from that as it was point out th= at our events don't fit well within the level gradient.=C2=A0 So the ne= w code for logging a compliance event does not use that level.=C2=A0 Both the compliance and business event would be logged a= t the Emergency level.=C2=A0 I would use the category property to different= iate them.=C2=A0 Similar, I guess, to log4j2's Markers.


Thanks,

Nick



From:= Dominik Psenner <dpsenner@gmail.com>
Sent: Saturday, October 22, 2016 1:29 PM
To: Log4NET User
Subject: Re: Injecting properties into LoggingEvent
=C2=A0

What I am proposing here are a mere ideas that will need fur= ther investigation. I have not tried any of these ideas. You will have to p= rioritize 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&q= uot; <nickdu@msn.com= > wrote:

Is there a way for me to inject properties into a LoggingEvent?=C2=A0 I&= #39;m trying to accomplish this without the user (of log4net) doing anythin= g special.=C2=A0 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.=C2=A0 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 prop= erty on the LoggingEvent to use for filtering.=C2=A0 This property would be= determined based on the level property.=C2=A0 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 di= fferent value for this property so for them I'm using this property for= filtering.=C2=A0 I don't have the same issue with these other events b= ecause they are logged via an extension method I provided on the ILog interface:


public static class Logging

{

=C2=A0=C2=A0=C2=A0 public static void LogEvent(this ILog logger, Categor= y category, IEvent evnt)

=C2=A0=C2=A0=C2=A0 {

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if ((category !=3D null) &= ;& (evnt !=3D null))

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 {

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 evnt.= SetCategory(category.Name);

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Loggi= ngEvent le =3D new LoggingEvent(null, logger.Logger.Respository,

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 logger.Logger.Name, Level.Emergency, evnt, null= );

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 le.Pr= operties["category"] =3D category.Name;

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 logge= r.Logger.Log(le);

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }

=C2=A0=C2=A0=C2=A0 }

}


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 LoggingEven= t to "criticalDiagnostic".=C2=A0 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 LoggingEven= t to "noncriticalDiagnostic".=C2=A0 Any way for me to do that aut= omagically?


I also posted this at:


http://stackoverflow.com/questions/40187597= /injecting-properties-into-log4nets-loggingevent


Thanks,

Nick

--001a113ad9284cd4cc053f881ca9--