views:

266

answers:

2

Anyone know if there's a fluent way of configuring log4net (appenders and all the properties for appenders etc...).

The xml is driving me crazy.

Or if not, does anyone know of a decent .Net logging framework that can easily be fluently configured and offer similar features to log4net?

+1  A: 

If you don't mind the dependency on Microsoft's Enterprise library, you could use the Logging Application Block. Configuration is still in XML, but you can edit through a graphical interface directly in Visual Studio,

kgiannakakis
+2  A: 

Cool cheers I'll take a look. Found what I was looking for in log4net too.

Annoyingly we've started using Castle Logging Facility which only seems to take a string to an xml file! So may have to consider doing it all via DSL and generating our xml configs as a pre build step.

    private static void ConfigureLog()
    {
        var root = ((Hierarchy)LogManager.GetRepository()).Root;
        root.AddAppender(GetConsoleAppender());
        root.AddAppender(GetFileAppender(@"d:\dev\huddle\log\Huddle.Sync", "standard.log", Level.Debug));
        root.AddAppender(GetFileAppender(@"d:\dev\huddle\log\Huddle.Sync", "error.log", Level.Warn));
        root.Repository.Configured = true;
    }

    private static FileAppender GetFileAppender(string directory, string fileName, Level threshold)
    {
        var appender = new FileAppender
        {
            Name = "File", 
            AppendToFile = true,
            File = directory + @"\" + fileName, 
            Layout = new PatternLayout(_pattern), 
            Threshold = threshold
        };

        appender.ActivateOptions();
        return appender;
    }

    private static ConsoleAppender GetConsoleAppender()
    {
        var appender = new ConsoleAppender
        {
            Name = "Console", 
            Layout = new PatternLayout(_pattern), 
            Threshold = Level.Debug
        };

        appender.ActivateOptions();
        return appender;
    }
Bealer