Created
August 10, 2013 09:51
-
-
Save krunalm/6199811 to your computer and use it in GitHub Desktop.
NLog => Sample Text Logger Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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