本文整理匯總了C#中NLog.Targets.FileTarget.WrapAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# FileTarget.WrapAsync方法的具體用法?C# FileTarget.WrapAsync怎麽用?C# FileTarget.WrapAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NLog.Targets.FileTarget
的用法示例。
在下文中一共展示了FileTarget.WrapAsync方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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 = LogManager.Configuration ?? new LoggingConfiguration();
if (!Debugger.IsAttached)
{
// create console target
var consoleTarget = new ColoredConsoleTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", logLevel, consoleTarget));
}
else
{
// create debugger target
var consoleTarget = new DebuggerTarget();
consoleTarget.Layout = layout;
config.AddTarget("console", consoleTarget);
config.LoggingRules.Add(new LoggingRule("*", logLevel, consoleTarget));
}
// 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, fileTarget.WrapAsync()));
// activate configuration and bind
LogManager.Configuration = config;
}