2

I have been looking at creating a common logging library for the company I work for, based on a blog by Daniel Cazzulino. so we can switch one out for another without to much disruption.

The first library I looked to use is log4net, but I cannot work out how or where you would setup a call to the XmlConfigurator.

I have tried adding an assembly on the project being logged, which kind of defeats the object of the exercise I feel, but that doesn't appear to work any way.

I have tried adding it as an assembly of the log4net Logging library, but that doesn't appear to work.

I have also tried calling log4net.Config.XmlConfigurator.Configure(); from the TraceManager.Get method, but all the log options (IsDebugEnabled, IsWarnEnabled, ...) are disabled.

public partial class TracerManager : ITracerManager
{
    /// <summary>
    /// Gets a tracer instance with the specified name.
    /// </summary>
    public ITracer Get(string name)
    {
        log4net.Config.XmlConfigurator.Configure();
        var logger = LogManager.GetLogger(name);
        return new Log4NetAdapter(logger);
    }
    /// The rest
}

Do I need to do something else? Does the app config need to be in in the logging library?

[Edit 1]

Feel very silly....

I'd added [assembly: XmlConfigurator(Watch = true)] to my Logging.Log4Net library, but I wasnt instantiating the TracerManager in my application on the tests I was performing... ID-10Tango issue

Luke Duddridge
  • 4,285
  • 35
  • 50
  • If you dissasemble http://nuget.org/packages/tracer.log4net you should be able to see how it's done – stuartd Jan 30 '13 at 11:09
  • There isnt anything to disassemble? the nuget package adds a TracerManager.cs to the project. – Luke Duddridge Jan 30 '13 at 11:28
  • The logging library certainly needs to be able to access the lognet config if it's going to do the configuration - would moving the config to it's own file make it easier? (Then you can use `log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(path_to_file));` which gives you the ability to change log levels etc at runtime) – stuartd Jan 30 '13 at 11:57
  • I feel very silly........... I wasnt instantiating TracerManager >. – Luke Duddridge Jan 30 '13 at 12:15
  • In the end I added `[assembly: XmlConfigurator(Watch = true)]` to my the Logger.Log4Net library and made sure I was instantiating TracerManager.... you can call me a div in the answer and I'll mark it as correct ;) – Luke Duddridge Jan 30 '13 at 12:16
  • 1
    We've all been there, glad you got it fixed. – stuartd Jan 30 '13 at 13:03

1 Answers1

0

I'd added [assembly: XmlConfigurator(Watch = true)] to my Logging.Log4Net library, but I wasnt instantiating the TracerManager in my application on the tests I was performing...

ID-10Tango issue

Luke Duddridge
  • 4,285
  • 35
  • 50