本文整理汇总了C#中NLog.Config.LoggingConfiguration类的典型用法代码示例。如果您正苦于以下问题:C# LoggingConfiguration类的具体用法?C# LoggingConfiguration怎么用?C# LoggingConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoggingConfiguration类属于NLog.Config命名空间,在下文中一共展示了LoggingConfiguration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NLogLogProviderLoggingEnabledTests
public NLogLogProviderLoggingEnabledTests()
{
NLogLogManager.ProviderIsAvailableOverride = true;
var config = new LoggingConfiguration();
simpleLayoutTarget = new MemoryTarget
{
Layout = "${level:uppercase=true}|${message}|${exception}"
};
ndcLayoutTarget = new MemoryTarget
{
Layout = "${level:uppercase=true}|${ndc:bottomFrames=10:topFrames=10:separator=;}|${message}|${exception}"
};
mdcLayoutTarget = new MemoryTarget
{
Layout = "${level:uppercase=true}|${mdc:item=Key}|${message}|${exception}"
};
config.AddTarget("simpleLayoutMemory", simpleLayoutTarget);
config.AddTarget("mdcLayoutTarget", mdcLayoutTarget);
config.AddTarget("ndcLayoutMemory", ndcLayoutTarget);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, simpleLayoutTarget));
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, mdcLayoutTarget));
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, ndcLayoutTarget));
LogManager.Configuration = config;
nLogLogManager = new NLogLogManager();
sut = nLogLogManager.GetLogger("Test");
}
示例2: InitializeLogging
public static void InitializeLogging() {
var config = new LoggingConfiguration();
Target debuggerTarget = new DebuggerTarget() {
Layout = "${longdate}|${level}|${logger}|${message} ${exception:format=tostring}"
};
Target consoleTarget = new ColoredConsoleTarget() {
Layout = "${longdate}|${level}|${logger}|${message} ${exception:format=tostring}"
};
#if !DEBUG
debuggerTarget = new AsyncTargetWrapper(debuggerTarget);
consoleTarget = new AsyncTargetWrapper(consoleTarget);
#else
new AsyncTargetWrapper().Wrap(); // Placeholder for optimizing imports
#endif
config.AddTarget("debugger", debuggerTarget);
config.AddTarget("console", consoleTarget);
var debuggerRule = new LoggingRule("*", LogLevel.Trace, debuggerTarget);
config.LoggingRules.Add(debuggerRule);
var consoleRule = new LoggingRule("*", LogLevel.Trace, consoleTarget);
config.LoggingRules.Add(consoleRule);
LogManager.Configuration = config;
}
示例3: Main
private static void Main(string[] args)
{
if (args.Length <= 0)
{
return;
}
var config = new LoggingConfiguration();
var logfile = new FileTarget();
var logdir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HearthstoneTracker");
logdir = Path.Combine(logdir, "logs");
var logfilename = Path.Combine(logdir, "updater.${date:format=yyyy-MM-dd}.txt");
logfile.FileName = logfilename;
logfile.CreateDirs = true;
logfile.MaxArchiveFiles = 7;
logfile.ArchiveEvery = FileArchivePeriod.Day;
logfile.ConcurrentWrites = true;
logfile.Layout =
"${longdate}|${level:uppercase=true}|thread:${threadid}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}";
config.AddTarget("logfile", logfile);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, logfile));
LogManager.Configuration = config;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new UpdateProgress(args));
}
示例4: SetupLogging
private void SetupLogging()
{
LoggingConfiguration configuration = new LoggingConfiguration();
NLogViewerTarget log_viewer_target = new NLogViewerTarget();
configuration.AddTarget("viewer", log_viewer_target);
log_viewer_target.Name = "viewer";
log_viewer_target.Address = "udp://127.0.0.1:9999";
LoggingRule log_viewer_rule = new LoggingRule("*", LogLevel.Trace, log_viewer_target);
configuration.LoggingRules.Add(log_viewer_rule);
if (!string.IsNullOrEmpty(LogFile))
{
FileTarget file_target = new FileTarget();
configuration.AddTarget("file", file_target);
file_target.FileName = LogFile;
file_target.Layout = "${message}";
file_target.DeleteOldFileOnStartup = true;
LoggingRule log_file_rule = new LoggingRule("*", LogLevel.Trace, file_target);
configuration.LoggingRules.Add(log_file_rule);
}
// Step 5. Activate the configuration
LogManager.Configuration = configuration;
}
示例5: ConfigLogging
private void ConfigLogging()
{
var config = new LoggingConfiguration();
var target = new DebuggerTarget
{
Layout = @"${date:format=HH\\:MM\\:ss} ${logger} ${message}"
};
var sqlTarget = new FileTarget
{
Layout = @"${date:format=HH\\:MM\\:ss} ${logger} ${message}",
FileName = "sql.log"
};
var rule = new LoggingRule( "*", LogLevel.Trace, target );
var sqlRule = new LoggingRule( "NHibernate", LogLevel.Trace, sqlTarget );
config.AddTarget( "sql", sqlTarget );
config.AddTarget( "debugger", target );
config.LoggingRules.Add( sqlRule );
config.LoggingRules.Add( rule );
LogManager.Configuration = config;
}
示例6: ConfigureForTargetLogging
/// <summary>
/// Configures NLog for to log to the specified target so that all messages
/// above and including the specified level are output.
/// </summary>
/// <param name="target">The target to log all messages to.</param>
/// <param name="minLevel">The minimal logging level.</param>
public static void ConfigureForTargetLogging(Target target, LogLevel minLevel)
{
LoggingConfiguration config = new LoggingConfiguration();
LoggingRule rule = new LoggingRule("*", minLevel, target);
config.LoggingRules.Add(rule);
LogManager.Configuration = config;
}
示例7: LoadLoggerToLoggingConfig
public static void LoadLoggerToLoggingConfig(LoggingConfiguration logConfig, IConfiguration Configuration,string sectionString)
{
var fileLoggerSection = Configuration.GetSection(sectionString).GetChildren();
foreach (var logging in fileLoggerSection)
{
var target = new FileTarget()
{
FileName = logging["fileName"],
Name = logging["name"],
Layout = logging["layoutFormat"]
};
var minLevel = logging["minLevel"] != null ? LogLevel.FromString(logging["minLevel"]) : null;
LoggingRule rule = null;
if (minLevel != null)
{
rule = new LoggingRule(logging["namePattern"], minLevel, target);
}
else
{
rule = new LoggingRule(logging["namePattern"], target);
}
var useLevels = logging["logLevel"];
if(string.IsNullOrWhiteSpace(useLevels) == false)
{
var levels = useLevels.Split(',');
foreach (var level in levels)
{
rule.EnableLoggingForLevel(LogLevel.FromString(level));
}
}
logConfig.AddTarget(target);
logConfig.LoggingRules.Add(rule);
}
}
示例8: Load
public override void Load()
{
// log layout format
var layout = "${date:format=hh\\:mm\\:ss tt} ${pad:padding=6:inner=${level:uppercase=true}} ${message} ${exception:separator=\r\n:format=message,type,method,stackTrace:maxInnerExceptionLevel=10:innerExceptionSeparator=\r\n:innerFormat=message,type,method,stackTrace}";
// initialize logging configuration
var config = new LoggingConfiguration();
// create console target
if (!Debugger.IsAttached)
{
var consoleTarget = new ColoredConsoleTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", this.logLevel, consoleTarget));
}
else
{
var consoleTarget = new DebuggerTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", this.logLevel, consoleTarget));
}
// activate configuration and bind
LogManager.Configuration = config;
}
示例9: InitLogging
private static void InitLogging()
{
var s_Config = new LoggingConfiguration();
var s_ConsoleTarget = new ColoredConsoleTarget();
s_Config.AddTarget("console", s_ConsoleTarget);
s_ConsoleTarget.Layout = @"[${date:format=HH\:mm\:ss.fff}] ${logger} >> ${message}";
var s_ConsoleRule = new LoggingRule("*", LogLevel.Trace, s_ConsoleTarget);
s_Config.LoggingRules.Add(s_ConsoleRule);
var s_FileTarget = new FileTarget();
s_Config.AddTarget("file", s_FileTarget);
s_FileTarget.FileName = "${basedir}/GrooveCaster.log";
s_FileTarget.Layout = @"[${date:format=HH\:mm\:ss.fff}] ${logger} >> ${message}";
s_FileTarget.ArchiveFileName = "${basedir}/GrooveCaster.{#}.log";
s_FileTarget.ArchiveEvery = FileArchivePeriod.Day;
s_FileTarget.ArchiveNumbering = ArchiveNumberingMode.Date;
s_FileTarget.ArchiveDateFormat = "yyyMMdd";
var s_FileRule = new LoggingRule("*", LogLevel.Trace, s_FileTarget);
s_Config.LoggingRules.Add(s_FileRule);
LogManager.Configuration = s_Config;
}
示例10: DependencyRegistry
/// <summary>
/// Constructs an instance of DependencyRegistry
/// </summary>
public DependencyRegistry(ConfigSettings configSettings)
{
string logFileTemplate = configSettings.LogFileTemplate ?? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "default.log");
string dataDirectory = configSettings.DataDirectory ?? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "configdata");
LogLevel logLevel = GetMatchingLogLevelOrDefault(configSettings.LogLevel) ?? LogLevel.Info;
For<IRepository<IJsonEntity<ConfigRoot>>>()
.Singleton()
.Use(new DurableMemoryRepository<ConfigRoot>(dataDirectory, new FileSystemFacade()));
var config = new LoggingConfiguration();
var fileTarget = new FileTarget();
fileTarget.Name = "LogFile";
fileTarget.FileName = logFileTemplate;
config.AddTarget(fileTarget.Name, fileTarget);
var loggingRule = new LoggingRule("*", logLevel, fileTarget);
config.LoggingRules.Add(loggingRule);
LogManager.Configuration = config;
For<ILogger>()
.Singleton()
.Use(l => new LoggerAdapter(LogManager.GetLogger(GetType().Namespace)));
// Ask StructureMap to always do property injection for certain properties
// TODO: remove this?
SetAllProperties(policy => policy.OfType<ILogger>());
}
示例11: Load
public override void Load()
{
// log layout format
var layout = "${date:format=hh\\:mm\\:ss tt} ${pad:padding=6:inner=${level:uppercase=true}} ${message} ${exception:separator=\r\n:format=message,type,method,stackTrace:maxInnerExceptionLevel=10:innerExceptionSeparator=\r\n:innerFormat=message,type,method,stackTrace}";
// initialize logging configuration
var config = new LoggingConfiguration();
// create debugger target
var debuggerTarget = new DebuggerTarget();
debuggerTarget.Layout = layout;
config.AddTarget("console", debuggerTarget);
config.LoggingRules.Add(new LoggingRule("*", logLevel, WrapAsync(debuggerTarget)));
// create file target
var fileTarget = new FileTarget() { AutoFlush = false };
fileTarget.Layout = layout;
fileTarget.FileName = Path.Combine(this.directory, "BitSharp.log");
fileTarget.DeleteOldFileOnStartup = true;
config.AddTarget("file", fileTarget);
config.LoggingRules.Add(new LoggingRule("*", logLevel, WrapAsync(fileTarget)));
// activate configuration and bind
LogManager.Configuration = config;
}
示例12: ConfigureLogging
private void ConfigureLogging()
{
var fileTarget = new FileTarget {
FileName = Path.Combine(GetLogFolder(), "log.xml"),
ArchiveFileName = "log_{#####}.xml",
ArchiveNumbering = ArchiveNumberingMode.Sequence,
ArchiveAboveSize = 1024*1024,
Layout = new Log4JXmlEventLayout()
};
var config = new LoggingConfiguration();
config.AddTarget("file", fileTarget);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, fileTarget));
var debuggerTarget = new DebuggerTarget();
config.AddTarget("debugger", debuggerTarget);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, debuggerTarget));
if (Debugger.IsAttached) {
var udpTarget = new NetworkTarget {
Address = "udp4://localhost:962",
Layout = new Log4JXmlEventLayout()
};
config.AddTarget("udp", udpTarget);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, udpTarget));
}
LogManager.Configuration = config;
PresentationTraceSources.DataBindingSource.Listeners.Add(new NLogTraceListener());
}
示例13: UsingNLog
public void UsingNLog()
{
var writer = GetTrace();
LoggingConfiguration config = new LoggingConfiguration();
TraceTarget target = new TraceTarget();
target.Layout = "NLOG [${level:uppercase=true}] ${message}";
config.AddTarget("trace", target);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, target));
LogManager.Configuration = config;
ConventionBuilder.Logger = t => LogManager.GetLogger(t);
var builder = new ConventionBuilder();
builder.ScanThisAssembly().For<HandlerConventions>();
var convention = builder.Build();
Approvals.VerifyAll(writer
.ToString()
.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.OrderBy(s => s), "");
}
示例14: SetupLogging
// ------------------------------------------
// Logs Management
// ------------------------------------------
protected void SetupLogging() {
var path = ConfigManager.GetInstance().Find("debug.log-file", null);
if (null == path) { return; }
LoggingConfiguration config = new LoggingConfiguration();
ColoredConsoleTarget consoleTarget = new ColoredConsoleTarget();
consoleTarget.Layout = "${date:format=HH\\:MM\\:ss} ${logger} ${message}";
config.AddTarget("console", consoleTarget);
FileTarget fileTarget = new FileTarget();
fileTarget.FileName = path;
fileTarget.Layout = "${message}";
fileTarget.CreateDirs = true;
config.AddTarget("file", fileTarget);
LoggingRule rule1 = new LoggingRule("*", LogLevel.Info, consoleTarget);
config.LoggingRules.Add(rule1);
LoggingRule rule2 = new LoggingRule("*", LogLevel.Info, fileTarget);
config.LoggingRules.Add(rule2);
LoggingRule rule3 = new LoggingRule("*", LogLevel.Warn, consoleTarget);
config.LoggingRules.Add(rule3);
LoggingRule rule4 = new LoggingRule("*", LogLevel.Warn, fileTarget);
config.LoggingRules.Add(rule4);
// Ready
LogManager.ReconfigExistingLoggers();
LogManager.Configuration = config;
Host.Log(this, "STARTING LOGGING:" + fileTarget.FileName);
}
示例15: NLogLogger
public NLogLogger()
{
ConfigurationItemFactory.Default.RegisterItemsFromAssembly(Assembly.GetExecutingAssembly());
var config = new LoggingConfiguration();
//var consoleTarget = new ColoredConsoleTarget();
//config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, consoleTarget));
var elasticTarget = new BufferingTargetWrapper(new ElasticSearchTarget
{
Fields =
{
new ElasticSearchField
{
Name = "application",
Layout = "LoggerAppNLog"
},
new ElasticSearchField
{
Name = "machinename",
Layout = "${machinename}"
},
}
}, 1000, 1000);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, elasticTarget));
LogManager.Configuration = config;
}