private string GetTag(LoggingEvent loggingEvent) { if (string.IsNullOrEmpty(_tagPropertyKey)) { _tagPropertyKey = Log4NetLoggerFactoryAdapter.GetTagParameterKey(loggingEvent.LoggerName); } string tag = null; if (ThreadContext.Properties.GetKeys()?.Any(p => p == _tagPropertyKey) == true) { tag = ThreadContext.Properties[_tagPropertyKey]?.ToString(); } else if (loggingEvent.Repository.Properties.Contains(_tagPropertyKey)) { tag = loggingEvent.Repository.Properties[_tagPropertyKey]?.ToString(); } if (string.IsNullOrEmpty(tag)) { tag = loggingEvent.Repository.Name; } return(tag); }
public static ILog GetLogger(Type type) { if (logger == null) { NameValueCollection properties = new NameValueCollection(); properties.Add("configType", "FILE-WATCH"); properties.Add("configFile", @"Resources\log4net.config"); Log4NetLoggerFactoryAdapter adapter = new Log4NetLoggerFactoryAdapter(properties); logger = adapter.GetLogger(type); } return(logger); }
public void TestSetUp() { _log4NetLoggerFactoryAdapter = new Log4NetLoggerFactoryAdapter(new NameValueCollection()); _nLogLoggerFactoryAdapter = new NLogLoggerFactoryAdapter(new NameValueCollection()); _multipleLoggerFactoryAdapter = new MultiLoggerFactoryAdapter(); _multipleLoggerFactoryAdapter.LoggerFactoryAdapters.Add(_log4NetLoggerFactoryAdapter); _multipleLoggerFactoryAdapter.LoggerFactoryAdapters.Add(_nLogLoggerFactoryAdapter); //these tests will only work if all of the loggers actually *support* VariablesContext with other than the No-Op 'placeholder' Assume.That(_log4NetLoggerFactoryAdapter.GetLogger(typeof(MultipleLoggerGlobalVariableContextTests)).GlobalVariablesContext, Is.Not.InstanceOf <NoOpVariablesContext>()); Assume.That(_nLogLoggerFactoryAdapter.GetLogger(typeof(MultipleLoggerGlobalVariableContextTests)).GlobalVariablesContext, Is.Not.InstanceOf <NoOpVariablesContext>()); }