Error Logger.Cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
using System.IO;
using System.Reflection;
namespace FireflyCacheClean
{
public class ErrorLogger
{
public static readonly ILog logger = LogManager.GetLogger(typeof(ErrorLogger));
String sConfFile = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\log4net.xml";
public ErrorLogger()
{
log4net.Config.XmlConfigurator.Configure(new FileInfo(sConfFile));
}
public void dologging(Object sMessage, Exception eException)
{
if (logger.IsDebugEnabled)
logger.Debug(sMessage, eException);
}
public void dologging(Object sMessage)
{
if (logger.IsDebugEnabled)
logger.Debug(sMessage.ToString());
}
public static void dologgings(Object sMessage)
{
if (logger.IsDebugEnabled)
logger.Debug(sMessage.ToString());
}
public void Logger()
{
logger.Info("Start Service");
// TODO: add code here
logger.Info("OrgChart stop");
Console.WriteLine("Press [Enter] to exit...");
Console.ReadLine();
}
}
}
LOG4NET XML
To ADD LOG4net DLL
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="true" threshold="ON">
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<!--<param name="File" value="H:\ffcache\log4net\log.txt" />-->
<param name="File" value="Precachelog.txt" />
<!--<file value="${APPDATA}\MyApp\MyApp Client\logs\Log.txt"/>-->
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{dd-MM-yyyy hh:mm:ss} – %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
</configuration>
To CALL This Way :
WriteLog("Clean Error :" + ex.ToString(), (int)DEBUG_LEVEL.ERROR);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
using System.IO;
using System.Reflection;
namespace FireflyCacheClean
{
public class ErrorLogger
{
public static readonly ILog logger = LogManager.GetLogger(typeof(ErrorLogger));
String sConfFile = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\log4net.xml";
public ErrorLogger()
{
log4net.Config.XmlConfigurator.Configure(new FileInfo(sConfFile));
}
public void dologging(Object sMessage, Exception eException)
{
if (logger.IsDebugEnabled)
logger.Debug(sMessage, eException);
}
public void dologging(Object sMessage)
{
if (logger.IsDebugEnabled)
logger.Debug(sMessage.ToString());
}
public static void dologgings(Object sMessage)
{
if (logger.IsDebugEnabled)
logger.Debug(sMessage.ToString());
}
public void Logger()
{
logger.Info("Start Service");
// TODO: add code here
logger.Info("OrgChart stop");
Console.WriteLine("Press [Enter] to exit...");
Console.ReadLine();
}
}
}
LOG4NET XML
To ADD LOG4net DLL
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="true" threshold="ON">
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<!--<param name="File" value="H:\ffcache\log4net\log.txt" />-->
<param name="File" value="Precachelog.txt" />
<!--<file value="${APPDATA}\MyApp\MyApp Client\logs\Log.txt"/>-->
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{dd-MM-yyyy hh:mm:ss} – %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
</configuration>
To CALL This Way :
WriteLog("Clean Error :" + ex.ToString(), (int)DEBUG_LEVEL.ERROR);
Comments
Post a Comment