Skip to content

Instantly share code, notes, and snippets.

@krunalm
Created August 10, 2013 09:51
Show Gist options
  • Save krunalm/6199811 to your computer and use it in GitHub Desktop.
Save krunalm/6199811 to your computer and use it in GitHub Desktop.
NLog => Sample Text Logger Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
namespace BrowserSessionTest
{
public static class Utils
{
private static Logger logger;
private static bool logInit = false;
private static Logger Logger
{
get
{
if (!logInit)
{
logger = LogManager.GetLogger("browserTestApp");
NLog.Targets.FileTarget fileTarget = new NLog.Targets.FileTarget();
fileTarget.Encoding = Encoding.Unicode;
fileTarget.Name = "FileTARGET";
fileTarget.CreateDirs = true;
fileTarget.FileName = @"${basedir}\logs\${date:format=yyyy}\${date:format=MM}\${date:format=yyyy.MM.dd}.log";
fileTarget.Layout = "${longdate} - ${logger} - ${level} - ${message} - ${exception:format=ToString,StackTrace}${newline}";
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(fileTarget);
logInit = true;
}
return logger;
}
}
public static void Info(string message)
{
Utils.Logger.Info(message);
}
public static void LogException(string message, Exception ex)
{
Utils.Logger.LogException(LogLevel.Error, message, ex);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment