using NLog;
using NLog.Config;
using NLog.Targets;
namespace MediaBrowser.Logging.Nlog
{
///
/// Class NlogManager
///
public static class NlogManager
{
///
/// Adds the file target.
///
/// The path.
/// if set to true [enable debug logging].
public static void AddFileTarget(string path, bool enableDebugLogging)
{
var logFile = new FileTarget();
logFile.FileName = path;
logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}";
AddLogTarget(logFile, "ApplicationLogFile", enableDebugLogging);
}
///
/// Adds the log target.
///
/// The target.
/// The name.
/// if set to true [enable debug logging].
private static void AddLogTarget(Target target, string name, bool enableDebugLogging)
{
var config = LogManager.Configuration;
config.RemoveTarget(name);
target.Name = name;
config.AddTarget(name, target);
var level = enableDebugLogging ? LogLevel.Debug : LogLevel.Info;
var rule = new LoggingRule("*", level, target);
config.LoggingRules.Add(rule);
LogManager.Configuration = config;
}
}
}