private Target WrapTargetAndRegister(Type logType, List <Target> targets, LoggerSettings.LogTargetConfigurationSet config) { if (targets == null) { return(null); } var internalLoggingEnabled = settingsProvider.Get(LoggerSettings.EnableNLogInternalLogging); Target buffer, asyncTarget, splitTarget, finalTarget; if (settingsProvider.Get(LoggerSettings.EnableNLogIndependentTragetWrite)) { var destinationTargets = targets.Select(t => { if (extraTargetWrapper != null) { t = extraTargetWrapper(t); } if (internalLoggingEnabled) { t = new TracingTarget(t); } buffer = CreateBufferTarget(t, logType, config); asyncTarget = CreateAsyncTarget(buffer, logType, config); return(asyncTarget); }); splitTarget = new OutSystemsSplitGroupTarget(destinationTargets.ToArray()); finalTarget = splitTarget; } else { var destinationTargets = targets.Select(t => { if (extraTargetWrapper != null) { return(extraTargetWrapper(t)); } return(t); }); splitTarget = new OutSystemsSplitGroupTarget(destinationTargets.ToArray()); if (internalLoggingEnabled) { splitTarget = new TracingTarget(splitTarget); } buffer = CreateBufferTarget(splitTarget, logType, config); asyncTarget = CreateAsyncTarget(buffer, logType, config); finalTarget = asyncTarget; } LogManager.Configuration.AddTarget(GetTargetNameUsedForConfiguration(logType), finalTarget); return(finalTarget); }
private void AddLogTarget(Type logType, List <Target> finalTargets, LoggerSettings.LogTargetConfigurationSet config) { if (finalTargets != null) // Only register targets if there are implementations { targets[logType] = WrapTargetAndRegister(logType, finalTargets, config); } }
private Target CreateBufferTarget(Target innerTarget, Type logType, LoggerSettings.LogTargetConfigurationSet config) { return(new BufferingTargetWrapper( innerTarget, settingsProvider.Get(config.MaxMessagesPerBatch), settingsProvider.Get(config.TimeToWaitBetweenBatchInMs), overflowAction: BufferingTargetWrapperOverflowAction.Flush) { Name = "BufferingTargetFor" + logType.Name, SlidingTimeout = false, OptimizeBufferReuse = true // Ensure targets are always optimized }); }
private Target CreateAsyncTarget(Target innerTarget, Type logType, LoggerSettings.LogTargetConfigurationSet config) { return(new AsyncTargetWrapper( innerTarget, settingsProvider.Get(config.MaxMessagesInQueue), ParseOverflowActionFromString( settingsProvider.Get(config.OnQueueOverflowAction))) { Name = "AsyncTargetFor" + logType.Name, FullBatchSizeWriteLimit = 15, OptimizeBufferReuse = true// Ensure targets are always optimized }); }