/// <summary> /// Create custom writer/wrapper if possible /// </summary> /// <param name="config">Writer or Wrapper configuration</param> /// <returns>Created wrapper of writer or Null</returns> private static ILoggingEventWriter CreateCustomWriter(LogWriterWrapperConfiguration config) { Contract.Requires(config != null); lock (_userFactories) { Func <LogWriterWrapperConfiguration, ILoggingEventWriter> factoryByType = null; if (_userFactories.TryGetValue(config.GetType(), out factoryByType)) { return(factoryByType(config)); } foreach (var factory in _userFactories) { var tmp = factory.Value(config); if (tmp != null) { return(tmp); } } } return(null); }
/// <summary> /// Create log Writer or Wrapper by its configuration /// </summary> /// <param name="config">Writer or Wrapper configuration</param> /// <returns>Created wrapper of writer</returns> internal static ILoggingEventWriter CreateWriter(LogWriterWrapperConfiguration config) { Contract.Requires <ArgumentNullException>(config != null, "configuration"); switch (config.WriterType) { case WriterTypeEnum.EmptyWriter: return(EmptyWriter.Instance); case WriterTypeEnum.AsyncQueueWrapper: return(new AsyncQueue((AsyncQueueWrapperConfiguration)config)); case WriterTypeEnum.AsyncQueueWithReliableSendingWrapper: return(new AsyncQueueWithReliableSending((AsyncReliableQueueWrapperConfiguration)config)); case WriterTypeEnum.ConsoleWriter: return(new ConsoleWriter((ConsoleWriterConfiguration)config)); case WriterTypeEnum.FileWriter: return(new FileWriter((FileWriterConfiguration)config)); case WriterTypeEnum.DBWriter: return(new DBWriter((DatabaseWriterConfiguration)config)); case WriterTypeEnum.PipeWriter: return(new PipeWriter((PipeWriterConfiguration)config)); case WriterTypeEnum.NetWriter: return(new NetWriter((NetWriterConfiguration)config)); case WriterTypeEnum.LogstashWriter: return(new LogstashWriter((LogstashWriterConfiguration)config)); case WriterTypeEnum.GroupWrapper: return(new GroupWriter((GroupWrapperConfiguration)config)); case WriterTypeEnum.RoutingWrapper: return(new RoutingWriter((RoutingWrapperConfiguration)config)); case WriterTypeEnum.PatternMatchingWrapper: return(new PatternMatchingWriter((PatternMatchingWrapperConfiguration)config)); case WriterTypeEnum.ReliableWrapper: return(new ReliableWrapper((ReliableWrapperConfiguration)config)); case WriterTypeEnum.CustomWrapper: case WriterTypeEnum.CustomWriter: var result = CreateCustomWriter(config); if (result == null) { throw new ArgumentException("Unknown type of custom logger Writer/Wrapper configuration: " + config.GetType().Name); } return(result); default: throw new ArgumentException("Unknown type of logger Writer/Wrapper configuration: " + config.WriterType.ToString()); } }