logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dave Brotherstone" <davebrotherst...@gmail.com>
Subject Correct point to add a custom property?
Date Thu, 03 Jan 2008 12:10:40 GMT
   We're trying to integrate log4net into our current application
framework.  We need to log an ID property against each log entry,
retrieved from the object we're trying to log.  This ID will
eventually go in a separate column in the database we're logging to.
To keep things simple, I'm currently using the FileAppender to test

Effectively we want to do :-

_logger.Warn(new LogItem(someGuid, someMessage));

And have a pattern layout (or database appender) to do something like :-

<layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger
[[%property{ID}]] - %message%newline" />

At the moment, I have this working by creating a new FileAppender,
inherting from FileAppender, and overriding the Append method with

protected override void Append(log4net.Core.LoggingEvent loggingEvent)
            loggingEvent.Properties["ID"] =

Are properties the right thing to use for this, or is there another
way? And if they are, is this the correct place to set them?
In reality, the LogItem object already exists when we want to log it,
so I'd rather not have to set the property before the _logger.Warn

I have searched through the archives, but haven't been able to find
anything doing the same thing, perhaps I'm searching for the wrong
thing though!

Many, many thanks,


View raw message