本文整理汇总了C#中NLog.Targets.Wrappers.AsyncTargetWrapper类的典型用法代码示例。如果您正苦于以下问题:C# AsyncTargetWrapper类的具体用法?C# AsyncTargetWrapper怎么用?C# AsyncTargetWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsyncTargetWrapper类属于NLog.Targets.Wrappers命名空间,在下文中一共展示了AsyncTargetWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: SetupNLog
private static Logger SetupNLog(NLogConfigurationApi config)
{
var logDirectory = string.IsNullOrEmpty(config.LogDirectory) ?
"${basedir}/Logs" :
config.LogDirectory;
var fileTarget = new FileTarget
{
Name = "FileTarget",
Layout = "${message}",
ConcurrentWrites = false,
FileName = new SimpleLayout(Path.Combine(logDirectory, "current.log")),
ArchiveEvery = config.ArchivePeriod,
ArchiveNumbering = ArchiveNumberingMode.Sequence,
MaxArchiveFiles = config.MaxArchiveFiles,
ArchiveFileName = new SimpleLayout(Path.Combine(logDirectory,"archive/{####}.log"))
};
var asyncWrapper = new AsyncTargetWrapper(fileTarget)
{
Name = "AsyncWrapper"
};
var loggingConfiguration = new LoggingConfiguration();
loggingConfiguration.AddTarget(LoggerName, asyncWrapper);
loggingConfiguration.LoggingRules.Add(new LoggingRule("*", LevelToNLogLevel(config.MinimumLogLevel), asyncWrapper));
LogManager.Configuration = loggingConfiguration;
return LogManager.GetLogger(LoggerName);
}
示例3: ConfigureNlog
public void ConfigureNlog(Logger logger)
{
FileTarget target = new FileTarget();
target.FileName = "${basedir}\\logs\\ICtrl.Log_${date:format=ddMMyyyy}.txt";
target.KeepFileOpen = false;
target.Encoding = "windows-1251";
target.Layout = "${date:format=HH\\:mm\\:ss.fff}|${level:padding=5:uppercase=true}|${message}";
AsyncTargetWrapper wrapper = new AsyncTargetWrapper();
wrapper.WrappedTarget = target;
wrapper.QueueLimit = 5000;
wrapper.OverflowAction = AsyncTargetWrapperOverflowAction.Block;
logOn = GetLogLevel();
switch (logOn)
{
case 1:
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(wrapper, LogLevel.Info);
break;
default:
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(wrapper, LogLevel.Off);
break;
}
}
示例4: AsyncTargetWrapperAsyncTest1
public void AsyncTargetWrapperAsyncTest1()
{
var myTarget = new MyAsyncTarget();
var targetWrapper = new AsyncTargetWrapper(myTarget) { Name = "AsyncTargetWrapperAsyncTest1_Wrapper" };
targetWrapper.Initialize(null);
myTarget.Initialize(null);
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
Assert.True(continuationHit.WaitOne());
Assert.Null(lastException);
Assert.Equal(1, myTarget.WriteCount);
continuationHit.Reset();
targetWrapper.WriteAsyncLogEvent(logEvent.WithContinuation(continuation));
continuationHit.WaitOne();
Assert.Null(lastException);
Assert.Equal(2, myTarget.WriteCount);
}
示例5: AsyncTargetWrapperAsyncTest1
public void AsyncTargetWrapperAsyncTest1()
{
var myTarget = new MyAsyncTarget();
var targetWrapper = new AsyncTargetWrapper(myTarget);
((ISupportsInitialize)targetWrapper).Initialize();
((ISupportsInitialize)myTarget).Initialize();
var logEvent = new LogEventInfo();
Exception lastException = null;
var continuationHit = new ManualResetEvent(false);
AsyncContinuation continuation =
ex =>
{
lastException = ex;
continuationHit.Set();
};
targetWrapper.WriteLogEvent(logEvent, continuation);
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(1, myTarget.WriteCount);
continuationHit.Reset();
targetWrapper.WriteLogEvent(logEvent, continuation);
continuationHit.WaitOne();
Assert.IsNull(lastException);
Assert.AreEqual(2, myTarget.WriteCount);
}
示例6: AsyncTargetWrapperInitTest
public void AsyncTargetWrapperInitTest()
{
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper(myTarget, 300, AsyncTargetWrapperOverflowAction.Grow);
Assert.Equal(AsyncTargetWrapperOverflowAction.Grow, targetWrapper.OverflowAction);
Assert.Equal(300, targetWrapper.QueueLimit);
Assert.Equal(50, targetWrapper.TimeToSleepBetweenBatches);
Assert.Equal(100, targetWrapper.BatchSize);
}
示例7: CreateRavenDbTarget
private static Target CreateRavenDbTarget(IDependencyResolver dependencyResolver, LoggingConfiguration loggingConfiguration)
{
var documentStore = (IDocumentStore)dependencyResolver.GetService(typeof(IDocumentStore));
var ravenDbTarget = new RavenDbTarget(documentStore);
var asyncWrapper = new AsyncTargetWrapper(ravenDbTarget, 1000, AsyncTargetWrapperOverflowAction.Discard);
loggingConfiguration.AddTarget("ravenDb", asyncWrapper);
return asyncWrapper;
}
示例8: MyTarget
public void AsyncTargetWrapperInitTest_WhenTimeToSleepBetweenBatchesIsEqualToZero_ShouldThrowNLogConfigurationException() {
LogManager.ThrowConfigExceptions = true;
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper() {
WrappedTarget = myTarget,
TimeToSleepBetweenBatches = 0,
};
Assert.Throws<NLogConfigurationException>(() => targetWrapper.Initialize(null));
}
示例9: AsyncTargetWrapperInitTest2
public void AsyncTargetWrapperInitTest2()
{
var myTarget = new MyTarget();
var targetWrapper = new AsyncTargetWrapper()
{
WrappedTarget = myTarget,
};
Assert.Equal(AsyncTargetWrapperOverflowAction.Discard, targetWrapper.OverflowAction);
Assert.Equal(10000, targetWrapper.QueueLimit);
Assert.Equal(50, targetWrapper.TimeToSleepBetweenBatches);
Assert.Equal(100, targetWrapper.BatchSize);
}
示例10: GetTargets
public IEnumerable<NLog.Targets.Target> GetTargets()
{
foreach (var target in this.targetConfigurations)
{
var asyncTargetWrapper = new AsyncTargetWrapper()
{
Name = target.Id.ToString(),
WrappedTarget = target.Type.GetConstructor(new Type[] { }).Invoke(null) as Target,
BatchSize = 1
};
yield return asyncTargetWrapper;
}
}
示例11: InitLogger
protected virtual NLogLogger InitLogger()
{
var wrapper = new AsyncTargetWrapper
{
Name = typeof (AsyncTargetWrapper).Name,
QueueLimit = 10000,
WrappedTarget = LoadTarget(),
OverflowAction = AsyncTargetWrapperOverflowAction.Grow
};
SimpleConfigurator.ConfigureForTargetLogging(wrapper);
LogManager.Configuration.LoggingRules.ForEachItem(lr => lr.EnableLoggingForLevel(LogLevel.Trace));
LogManager.ReconfigExistingLoggers();
return LogManager.GetLogger(LoggerName);
}
示例12: LogService
public LogService(Model m)
{
LoggingConfiguration config = LogManager.Configuration;
target = new LogServiceTarget(m.Messages);
target.Layout =
"${level}=> ${message} ${exception:format=Message} ${exception:format=Type} ${exception:format=StackTrace}";
target.Name = "LogService";
var wrapper = new AsyncTargetWrapper(target);
config.AddTarget("LogService", wrapper);
rule = new LoggingRule("*", LogLevel.Trace, target);
config.LoggingRules.Add(rule);
LogManager.Configuration = config;
if (Debugger.IsAttached)
target.Filter = LogLevel.Debug;
}
示例13: Main
static void Main(string[] args)
{
FileTarget target = new FileTarget();
target.Layout = "${longdate} ${logger} ${message}";
target.FileName = "${basedir}/logs/logfile.txt";
target.KeepFileOpen = false;
target.Encoding = Encoding.UTF8;
AsyncTargetWrapper wrapper = new AsyncTargetWrapper();
wrapper.WrappedTarget = target;
wrapper.QueueLimit = 5000;
wrapper.OverflowAction = AsyncTargetWrapperOverflowAction.Discard;
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(wrapper, LogLevel.Debug);
Logger logger = LogManager.GetLogger("Example");
logger.Debug("log message");
}
示例14: ConfigureCaptureTarget
private void ConfigureCaptureTarget()
{
captureTarget = new CaptureTarget
{
Layout = "${date}|${level:uppercase=true}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}"
};
captureTarget.LogReceived += target_LogReceived;
var asyncWrapper = new AsyncTargetWrapper { Name = "CaptureTargetWrapper", WrappedTarget = captureTarget };
LogManager.Configuration.AddTarget(asyncWrapper.Name, asyncWrapper);
currentLogLevel = NLog.LogLevel.Info;
loggingRule = new LoggingRule("*", currentLogLevel, asyncWrapper);
LogManager.Configuration.LoggingRules.Insert(0, loggingRule);
LogManager.ReconfigExistingLoggers();
PropertyChanged += OnPropertyChanged;
#if DEBUG
DebugEnabled = true;
#endif
}
示例15: Initialize
public void Initialize(string logFilesDirectory)
{
var config = new LoggingConfiguration();
this.logfile = new FileTarget();
var logfilename = Path.Combine(logFilesDirectory, "${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}}";
var asyncTarget = new AsyncTargetWrapper(logfile)
{
OverflowAction = AsyncTargetWrapperOverflowAction.Grow
};
config.AddTarget("logfile", asyncTarget);
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, asyncTarget));
//#if DEBUG
// var tracelogfile = new FileTarget();
// tracelogfile.FileName = Path.Combine(logFilesDirectory, "${date:format=yyyy-MM-dd}_Trace.txt");
// tracelogfile.CreateDirs = true;
// tracelogfile.MaxArchiveFiles = 7;
// tracelogfile.ArchiveEvery = FileArchivePeriod.Day;
// tracelogfile.ConcurrentWrites = true;
// tracelogfile.Layout =
// "${longdate}|${level:uppercase=true}|thread:${threadid}|${logger}|${message}${onexception:inner=${newline}${exception:format=tostring}}";
// var asyncTarget2 = new AsyncTargetWrapper(tracelogfile)
// {
// OverflowAction = AsyncTargetWrapperOverflowAction.Grow
// };
// config.AddTarget("tracelogfile", asyncTarget2);
// config.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, asyncTarget2));
//#endif
LogManager.Configuration = config;
// Caliburn.Micro.LogManager.GetLog = type => new NLogger(type);
}