You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Mohit Mehra <mo...@gmail.com> on 2005/10/11 19:49:49 UTC

Dynamically add Souce and Category to EventLog

Hello There,
I am using the most recent version of Log4Net. I need to be able to add
source and category information on a per message basis. I am able to
successfully add this in the SQL server as I can utilize MDC properties.
Example:

MDC.Set("category", category);

Can I do something similar to EventLogAppender?

 Thanks in advance.

 Mohit

Re: Dynamically add Souce and Category to EventLog

Posted by Mohit Mehra <mo...@gmail.com>.
The idea is to use the same Logger for multiple applications (Windows
Services, Web Services etc). For example System event log has sources like
DCOM, SCM, IIS etc. I would give extending EventLogAppender a try though.
 Thanks.

 On 10/11/05, Ron Grabowski <ro...@yahoo.com> wrote:
>
> There's this:
>
> /// <summary>
> /// Property used to set the Application name. This appears in the
> /// event logs when logging.
> /// </summary>
> /// <value>
> /// The string used to distinguish events from different sources.
> /// </value>
> /// <remarks>
> /// Sets the event log source property.
> /// </remarks>
> public string ApplicationName
> {
> get { return m_applicationName; }
> set { m_applicationName = value; }
> }
>
> Do you want the event source to be different for each log message? I
> don't think that's a correct usage for the event source. If you need to
> do that, I would extend EventLogAppender and override its Append
> method. I would check for an ApplicationName as a property of the
> loggingEvent or use the default value set in the config file if there
> isn't one:
>
> // untested...
> string applicationName =
> loggingEvent.LookupProperty("ApplicationName") as string;
> if (applicationName == null || applicationName.Length == 0)
> {
> // use the default value
> applicationName = ApplicationName;
> }
>
> // snip
>
> EventLog.WriteEntry(applicationName, eventTxt, entryType, eventID);
>
> --- Mohit Mehra <mo...@gmail.com> wrote:
>
> > Ron,
> > Thanks for your prompt replay. Although I have seen a lot of posts
> > regarding
> > EventId, I still don't see anything related to setting the Source
> > dynamically. Can you please post me some code or redirect to a URL?
> > Regards,
> > Mohit
> >
> >
> > On 10/11/05, Ron Grabowski <ro...@yahoo.com> wrote:
> > >
> > > This is being addressed in this thread:
> > >
> > > http://tinyurl.com/da3hj
> > >
> > >
> >
>
> http://www.mail-archive.com/log4net-user%40logging.apache.org/msg02455.html
> > >
> > > There has also been an issue opened on this since June 2005:
> > >
> > > http://issues.apache.org/jira/browse/LOG4NET-38
> > >
> > > --- Mohit Mehra <mo...@gmail.com> wrote:
> > >
> > > > Hello There,
> > > > I am using the most recent version of Log4Net. I need to be able
> > to
> > > > add
> > > > source and category information on a per message basis. I am able
> > to
> > > > successfully add this in the SQL server as I can utilize MDC
> > > > properties.
> > > > Example:
> > > >
> > > > MDC.Set("category", category);
> > > >
> > > > Can I do something similar to EventLogAppender?
> > > >
> > > > Thanks in advance.
> > > >
> > > > Mohit
> > > >
> > >
> > >
> >
>
>

Re: Dynamically add Souce and Category to EventLog

Posted by Ron Grabowski <ro...@yahoo.com>.
There's this:

 /// <summary>
 /// Property used to set the Application name.  This appears in the
 /// event logs when logging.
 /// </summary>
 /// <value>
 /// The string used to distinguish events from different sources.
 /// </value>
 /// <remarks>
 /// Sets the event log source property.
 /// </remarks>
 public string ApplicationName
 {
  get { return m_applicationName; }
  set { m_applicationName = value; }
 }

Do you want the event source to be different for each log message? I
don't think that's a correct usage for the event source. If you need to
do that, I would extend EventLogAppender and override its Append
method. I would check for an ApplicationName as a property of the
loggingEvent or use the default value set in the config file if there
isn't one:

 // untested...
 string applicationName = 
  loggingEvent.LookupProperty("ApplicationName") as string;
 if (applicationName == null || applicationName.Length == 0)
 {
  // use the default value
  applicationName = ApplicationName;
 }

 // snip

 EventLog.WriteEntry(applicationName, eventTxt, entryType, eventID);

--- Mohit Mehra <mo...@gmail.com> wrote:

> Ron,
> Thanks for your prompt replay. Although I have seen a lot of posts
> regarding
> EventId, I still don't see anything related to setting the Source
> dynamically. Can you please post me some code or redirect to a URL?
>  Regards,
> Mohit
> 
> 
>  On 10/11/05, Ron Grabowski <ro...@yahoo.com> wrote:
> >
> > This is being addressed in this thread:
> >
> > http://tinyurl.com/da3hj
> >
> >
>
http://www.mail-archive.com/log4net-user%40logging.apache.org/msg02455.html
> >
> > There has also been an issue opened on this since June 2005:
> >
> > http://issues.apache.org/jira/browse/LOG4NET-38
> >
> > --- Mohit Mehra <mo...@gmail.com> wrote:
> >
> > > Hello There,
> > > I am using the most recent version of Log4Net. I need to be able
> to
> > > add
> > > source and category information on a per message basis. I am able
> to
> > > successfully add this in the SQL server as I can utilize MDC
> > > properties.
> > > Example:
> > >
> > > MDC.Set("category", category);
> > >
> > > Can I do something similar to EventLogAppender?
> > >
> > > Thanks in advance.
> > >
> > > Mohit
> > >
> >
> >
> 


Re: Dynamically add Souce and Category to EventLog

Posted by Mohit Mehra <mo...@gmail.com>.
Ron,
Thanks for your prompt replay. Although I have seen a lot of posts regarding
EventId, I still don't see anything related to setting the Source
dynamically. Can you please post me some code or redirect to a URL?
 Regards,
Mohit


 On 10/11/05, Ron Grabowski <ro...@yahoo.com> wrote:
>
> This is being addressed in this thread:
>
> http://tinyurl.com/da3hj
>
> http://www.mail-archive.com/log4net-user%40logging.apache.org/msg02455.html
>
> There has also been an issue opened on this since June 2005:
>
> http://issues.apache.org/jira/browse/LOG4NET-38
>
> --- Mohit Mehra <mo...@gmail.com> wrote:
>
> > Hello There,
> > I am using the most recent version of Log4Net. I need to be able to
> > add
> > source and category information on a per message basis. I am able to
> > successfully add this in the SQL server as I can utilize MDC
> > properties.
> > Example:
> >
> > MDC.Set("category", category);
> >
> > Can I do something similar to EventLogAppender?
> >
> > Thanks in advance.
> >
> > Mohit
> >
>
>

Re: Dynamically add Souce and Category to EventLog

Posted by Ron Grabowski <ro...@yahoo.com>.
This is being addressed in this thread:

http://tinyurl.com/da3hj
http://www.mail-archive.com/log4net-user%40logging.apache.org/msg02455.html

There has also been an issue opened on this since June 2005:

http://issues.apache.org/jira/browse/LOG4NET-38

--- Mohit Mehra <mo...@gmail.com> wrote:

> Hello There,
> I am using the most recent version of Log4Net. I need to be able to
> add
> source and category information on a per message basis. I am able to
> successfully add this in the SQL server as I can utilize MDC
> properties.
> Example:
> 
> MDC.Set("category", category);
> 
> Can I do something similar to EventLogAppender?
> 
>  Thanks in advance.
> 
>  Mohit
>