Click here to Skip to main content
15,936,802 members
Articles / Desktop Programming / Windows Forms

Log4net GUI Configuration Tool

Rate me:
Please Sign up or sign in to vote.
2.58/5 (10 votes)
30 Nov 2006Apache4 min read 71K   1.9K   45   6
A tool can save your effort on configuring log4net.

log4net editor in MMC

logger editor


Log4net is really a wonderful tool library for developers, and I have gotten lots of benifit from it for serveral developing projects. Since it provides flexiable, powerful log mechanism, it also provides a complex and unfriendly configuration way in XML. It's not easy to push those junior developers to lever this library well, and the learning curve is too cliffy to know all features of it in a short time. I can't find any GUI tool to assist config log4net as WinCVS does for CVS, so I write a simple one for my company. Insteading of releasing an executive file directly, I release it as DLL library. It makes possible to integrate/merge/embed this GUI tool in your project or product, and make usage extensively. You may see how I integrate it into MMC (Microsoft Management Console) at the above picture.


You better have the concept knowledge of using log4net before use this library. At least, you should know the meanings of "Appender" and "logger". It's an open source project hosted by Apache. You may search log4net on Google for detail information.

Before using this editor, you have to download log4net.dll from its project site, and put this dll in the same folder with log4netConfigConsulter.dll, or install log4net.dll into GAC by using gacutil.exe (a tool from .NET SDK).

Using the Tool

There're only 2 Winform UI to do all configuration for log4net:

Appender Editor
Appender Editor's screen shot
Logger Editor
Logger Editor's screen shot

I suppose you have known how log4net work and how to use GUI, I'm not going to talk about GUI operation any more. Each control has its own tooltip when your mouse over it, it's my only hint about GUI for you. Let's talk about how to extend this tool by next paragraph!

Using the Code

There're 3 projects named log4netConfigConsulter, log4netEditor, and l4nEditor.

  1. log4netConfigConsulter: It could be the kernel one. There is an appenderConsulter class to handle all configuration detail in log4net.
  2. log4netEditor: This is GUI.
  3. l4nEditor: This is a demo project to show how to embed log4netEditor in an execution way.

There're serveral different appenders in log4net and it could have more in the future. So, for purpose on extensibility, I stored all parameters usage of known appenders in description files with XML.

You may find a folder AppenderInfo, it must be placed in the same folder with log4netConfigConsulter.dll. Let's examine a sample named RollingFileAppender.xml:

<?xmlversion="1.0" encoding="utf-8" ?>
        This Appender will write log information into physical files.
        <Argument Name="file" DataType="string" Value="C:\ws.log" 
            EnumValues="" Description=
            "The full path of plain-text file which you want to 
            store log information." UIType="SingleLineTextBox" 
            IsTagName="true" ValueAttriName="value"/>
        <Argument Name="appendToFile" DataType="bool" Value="true" 
            EnumValues="true;false" Description=
            "Append or overwrite if the log file was existed." 
            UIType="DropDownList" IsTagName="true" ValueAttriName="value"/>
        <Argument Name="rollingStyle" DataType="string" Value="Size" 
            EnumValues="Size;Date;Composite" Description=
            "Assign the condition which make file rolling." 
            UIType="DropDownList" IsTagName="true" ValueAttriName="value"/>
        <Argument Name="lockingModel" DataType="string" 
            EnumValues="" Description=
            "Indicate the lock mode of this log file." 
            UIType="SingleLineTextBox" IsTagName="true" ValueAttriName="type"/>
        <Argument Name="maxSizeRollBackups" DataType="int" Value="2" 
            EnumValues="" Description=
            "Indicate to keep how many log files." UIType="SingleLineTextBox" 
            IsTagName="true" ValueAttriName="value"/>
        <Argument Name="staticLogFileName" DataType="bool" Value="true" 
            EnumValues="true;false" Description=
            "True if always should be logged to the same file, otherwise false."
            UIType="DropDownList" IsTagName="true" ValueAttriName="value"/>
        <Argument Name="maximumFileSize" DataType="string" Value="128KB" 
            EnumValues="" Description=
            "The maximum size that the output file is allowed to reach 
            before being rolled over to backup files."
            UIType="SingleLineTextBox" IsTagName="true" ValueAttriName="value"/>

The part of those information in the XML are extracted on Editor UI:
appender editor UI

Now you can see how my editor UI was generated by the indication in XML. Since you may produce/customerize your own appender in log4net, you may extend my editor to support the one by only creating a new XML info file. There're some other attributes in XML to indicate how my editor to produce the Xml configuration format which is needed by log4net.

IsTagName={true | false}

<Argument Name="file" ... Value="C:\ws.log" ... IsTagName=
    "{true | false}" ValueAttriName="value"/>
  • true: Editor will save log4net configuration as following by using Argument[Name] to be prefix:
    <file value="C:\ws.log" />
  • false: Editor will save log4net configuration as following:
    <param Name="file" value="C:\ws.log" />


Let's see example directly:

<Argument Name="file" ... Value="C:\ws.log" ... IsTagName="true" 

Then <file YourValueName="C:\ws.log" />

Variable or class names should be wrapped in <code> tags like this.

Points of Interest

For extensibility, I use Reflection to enumerate all supported appenders on user's environment. When you download new version of log4net with new appenders, this tool can enumerate them automatically without you doing anything. But how can it know the configurations of those new unknown appenders? No, it can't. It will treat them as OutputdebugString Appender and use the most common configuration for them till someone creates their own XML info files in AppenderInfo folder. I'm glad to get any feedback if you used my little tool on your task. Please let me know if you have any idea, opinion, feeling, etc. However, it just only a prototype, I wish someone can join enhancing it.




This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0

Written By
Technical Lead TutorGroup
Taiwan Taiwan
I focus high performance and heavy transaction system platform. DotNet is my professional skill territory.

But, I'm still interested in all kind of programming.

Comments and Discussions

GeneralMy vote of 1 Pin
Vladwalross14-Apr-14 4:06
Vladwalross14-Apr-14 4:06 
GeneralYou need compile a new one for latest log4net dll Pin
Tom Tang API5-May-14 16:58
Tom Tang API5-May-14 16:58 
GeneralThanks4YourTool Pin
bigthor29-Oct-08 22:19
bigthor29-Oct-08 22:19 
Generalhello Pin
Donny liu6-May-08 19:17
Donny liu6-May-08 19:17 
QuestionRe: hello Pin
Tom Tang API17-Jul-08 21:19
Tom Tang API17-Jul-08 21:19 
GeneralRe: hello Pin
Tom Tang API5-May-14 16:59
Tom Tang API5-May-14 16:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.