Create a Windows Forms Application project named "Sample" using Visual Studio (the code is in c#).
Step 2
Get log4net library by either downloading it from https://logging.apache.org/log4net/ or by installing the package through NuGet Package Manager.
Step 3
Create folder "lib" under the project and place files there.
Add reference to lib\log4net.dll
Step 4
Please rename default form to "FrmSample". On the default form add a button and a RichTextBox.
Please name the RichTextBox as "RtbOutput" and a button as "CmdGenerateTestLogs".
Step 5
In the root of the project folder create XML file: log4net.config
In Properties for the file set: Copy to Output Directory: Copy if newer
Populate file with following (log file appender will create a file in logs folder with the file name of output.log; once file size reaches 10MB, new file will be created. Maximum of 10 log files will be retained). Please change "Sample" with the name of your project namespace, form name "FrmSample" with the name of the windows form name, text box name "RtbOutput" with the name of the RichTextBox that would be used to output log4net messages:
Open the code behind the form by pressing F7 on the form and paste following code:
usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;usinglog4net;namespaceSample{publicpartialclassFrmSample:Form{privatestaticreadonlyILogLog=LogManager.GetLogger(typeof(FrmSample));publicFrmSample(){InitializeComponent();#region Set properties for RtbOutput as per your choiceRtbOutput.BackColor=System.Drawing.SystemColors.Control;RtbOutput.HideSelection=false;RtbOutput.ReadOnly=true;RtbOutput.Text="";RtbOutput.WordWrap=false;RtbOutput.Font=newFont(FontFamily.GenericMonospace,9);#endregion}privatevoidCmdGenerateTestLogs_Click(objectsender,EventArgse){Log.Debug("This is a DEBUG message");Log.Info("This is a INFO message");Log.Warn("This is a WARN message");Log.Error("This is a ERROR message");Log.Fatal("This is a FATAL message");}}}
Step 9
Running program and clicking on the button should print out the log (same log will appear in the output.log file under log folder - check the project output directory). Feel free to modify the properties of the RichTextBox as you fit.