(1)
Here's another way of storing extra information with the logging event:
// untested
public void Info(object message, Exception ex, object additional)
{
if (Logger.IsEnabledFor(Level.Info))
{
LoggingEvent loggingEvent = new LoggingEvent(
declaringType,
Logger.Repository,
Logger.Name,
Level.Info,
message,
ex);
loggingEvent.Properties["additional"] = additional;
Logger.Log(loggingEvent);
}
}
(2)
(3)
If the call looks like this:
log.Info("Oh no!", ex, 1234);
I can access 1234 by using the property pattern:
<conversionPattern value="%property{additional}" />
(4)
If you configure log4net using the ConfigureAndWatch method:
XmlConfigurator.ConfigureAndWatch(
new FileInfo(
AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
"log4net.config"));
log4net will attempt to reload itself when the configuration file
changes.
--- puska <[EMAIL PROTECTED]> wrote:
> Hi
>
> What I'm trying to do is to include new field (column) in Sql DB,
> with some
> additional business related information.
> I need this optional info (parameter) in NEW column for fastest
> browsing and
> searching.
> Idea is to call log from application with new parameter:
> log.Info("My message","Some business data");
> // or log.Info("My message", ex, "Some business data"); // with
> Exception
>
> I'm already using custom wrapper for log4net, so I easily overloaded
> Info
> function:
> public void Info(object message, Exception ex, object additional)
> {
> using
> (log4net.LogicalThreadContext.Stacks["additional"].Push(
> additional.ToString()))
> {
> this.Logger.Logger.Log(
> _declaringType,
> log4net.Core.Level.Info,
> message,
> ex);
> }
> }
>
> and I put new parameter in SQLAdoAppender (in config file):
> <parameter>
> <parameterName value="@Additional" />
> <dbType value="String" />
> <size value="1024" />
> <layout type="log4net.Layout.PatternLayout">
> <conversionPattern value="%property" />
> </layout>
> </parameter>
>
> and this is working (almost) fine.
>
> My questions are:
> 1. Is there any better (fastest) way for doing this?
> 2. My additional parameter is strictly related to called logging
> event.
> Would I have on this way interference with other logs?
> 3. How to get only my additional info from property? I tried this,
> but it's
> not working:
> <conversionPattern value="%property{additional}" />
> 4. when I make some error in configuration file (like one above) and
> then
> correct it, logging won't work until I restart my web application?!
>
> Thanks, Mario
>
>
> PS I'm using log4net-1.2.10 in my ASP.NET 2.0 application
>