Monday, 20 October 2008

How to use Log4net

First, create a configuration file with name "ApplicationName.exe.config"



































In the main class declare

using log4net.Config;
using System.IO;
using log4net.Core;
using log4net.Repository;

// Registers Logger for logging
private static readonly log4net.ILog logger = log4net.LogManager.GetLogger(typeof(PCSCoreSimulator));

private void StartLog()
{
string fullPath = Application.ExecutablePath + ".config";
XmlConfigurator.ConfigureAndWatch(new FileInfo(filePath));
}


private void TestLog()
{
logger.Error("Error");
logger.Info("Infor");
...
}

No comments: