/// <summary> /// Detach from the logging event source. /// Implicitly take a snapshot. /// </summary> public void Detach() { if (_appender == null) { throw new InvalidOperationException("Not attached"); } // RemoveAppender throws an exception if the appender // to be removed is not in the list of appenders! Interceptor.RemoveAppender(_appender); TakeSnapshot(); _appender = null; }
public void Attach() { // TODO Params to attach to specific repository/logger? if (_appender != null) { throw new InvalidOperationException("Already attached"); } // This should use the proper logger repository and // it's a no-op if the appender is already attached: Log4NetUtils.AddRootAppender(Interceptor); var appender = new BufferAppender(Math.Max(1, Capacity), DateTime.Now); var guid = Guid.NewGuid().ToString("N"); // hex digits only appender.Name = $"Inspector_{guid}"; appender.Threshold = ConvertLevel(Threshold); if (!string.IsNullOrEmpty(LoggerPrefix)) { appender.AddFilter(new LoggerMatchFilter { LoggerToMatch = LoggerPrefix }); appender.AddFilter(new DenyAllFilter()); } // An appender's Threshold and Filter chain interact as follows: // 1. ignore e if e.Level < a.Threshold // 2. walk filter chain until first Accept or Deny // 3. PreAppendCheck() and exit if false // 4. call Append(e) Interceptor.AddAppender(appender); // Just for the record: // Adding the same instance again is a no-op. Adding another // instance with the *same name* will be added to the list! _appender = appender; }