private void RecordEventSource(ICommonLoggingEventSource candidate) { //if we have a valid object if (candidate != null) { var eventSourceType = candidate.GetType(); //if we don't already have an instance of this same type in the registry... if (!EventSourceRegistry.ContainsKey(eventSourceType)) { //...add it EventSourceRegistry.Add(eventSourceType, candidate); } else { //if the incoming instance is _not_ the same instance as that already registered... if (EventSourceRegistry[eventSourceType] != candidate) { //...react accordingly to the attempted duplicate registration ThrowIfDuplicateEventSourceTypeRegistrationNotPermitted(eventSourceType); } //if we get this far, replace the existing instance with the new instance EventSourceRegistry[eventSourceType] = candidate; } //set the type designator so we can keep track of the correct EventSource Type for this adapter _eventSourceType = eventSourceType; } }
private void ConfigureEventSource(NameValueCollection properties) { //assign an instance of a custom ICommonLoggingEventSource if specified, else use default type var commonLoggingEventSourceTypeDescriptor = ArgUtils.GetValue(properties, "commonLoggingEventSourceType", string.Empty); if (!string.IsNullOrEmpty(commonLoggingEventSourceTypeDescriptor)) { var eventSourceType = Type.GetType(commonLoggingEventSourceTypeDescriptor); if (null == eventSourceType) { throw new ConfigurationException( string.Format( "Error in 'commonLoggingEventSourceType' arg. Unable to determine TYPE information from value {0}", commonLoggingEventSourceTypeDescriptor)); } try { var candidate = Activator.CreateInstance(eventSourceType) as ICommonLoggingEventSource; RecordEventSource(candidate); } catch (Exception exception) //no matter the underlying exception type we want to report it as a Config Exception { throw new ConfigurationException("Error in 'commonLoggingEventSourceType' arg.", exception); } } else { var defaultEventSourceType = typeof(CommonLoggingEventSource); if (!EventSourceRegistry.ContainsKey(defaultEventSourceType)) { EventSource = new CommonLoggingEventSource(); } _eventSourceType = defaultEventSourceType; } }
public ETWLogger(ICommonLoggingEventSource eventSource, LogLevel logLevel) { _eventSource = eventSource; _logLevel = logLevel; }
public ETWLogger(ICommonLoggingEventSource eventSource) : this(eventSource, LogLevel.All) { }
public ETWLoggerFactoryAdapter(NameValueCollection properties) : base(true) { //assign an instance of a custom ICommonLoggingEventSource if specified, else use default type var commonLoggingEventSourceTypeDescriptor = ArgUtils.GetValue(properties, "commonLoggingEventSourceType", string.Empty); if (!string.IsNullOrEmpty(commonLoggingEventSourceTypeDescriptor)) { var type = Type.GetType(commonLoggingEventSourceTypeDescriptor); if (null == type) { throw new ConfigurationException( string.Format( "Error in 'commonLoggingEventSourceType' arg. Unable to determine TYPE information from value {0}", commonLoggingEventSourceTypeDescriptor)); } try { var candidate = Activator.CreateInstance(type) as ICommonLoggingEventSource; if (candidate != null) { ETWEventSource = candidate; } } catch (Exception exception) //no matter the underlying exception type we want to report it as a Config Exception { throw new ConfigurationException("Error in 'commonLoggingEventSourceType' arg.", exception); } } else { ETWEventSource = new CommonLoggingEventSource(); } //set the logging level; default to ALL var levelSetting = ArgUtils.TryParseEnum(LogLevel.All, ArgUtils.GetValue(properties, "level")); switch (levelSetting) { case LogLevel.Trace: case LogLevel.All: LogLevel = LogLevel.Trace | LogLevel.Debug | LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal; break; case LogLevel.Debug: LogLevel = LogLevel.Debug | LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal; break; case LogLevel.Info: LogLevel = LogLevel.Info | LogLevel.Warn | LogLevel.Error | LogLevel.Fatal; break; case LogLevel.Warn: LogLevel = LogLevel.Warn | LogLevel.Error | LogLevel.Fatal; break; case LogLevel.Error: LogLevel = LogLevel.Error | LogLevel.Fatal; break; case LogLevel.Fatal: LogLevel = LogLevel.Fatal; break; case LogLevel.Off: default: break; } }