public void CheckThreadVariablesSet() { var a = new NLogLoggerFactoryAdapter((Common.Logging.Configuration.NameValueCollection)null); a.GetLogger(this.GetType()).ThreadVariablesContext.Set("TestKey", "TestValue"); // NLog10 doesn't support this. This test only makes sure that no exceptions are thrown }
public void CheckNestedThreadVariablesSet() { var a = new NLogLoggerFactoryAdapter((NameValueCollection) null); var hasItems = a.GetLogger(this.GetType()).NestedThreadVariablesContext.HasItems; Assert.AreEqual(false, hasItems); a.GetLogger(this.GetType()).NestedThreadVariablesContext.Push("TestValue1"); hasItems = a.GetLogger(this.GetType()).NestedThreadVariablesContext.HasItems; Assert.AreEqual(true, hasItems); a.GetLogger(this.GetType()).NestedThreadVariablesContext.Push("TestValue2"); int depth = global::NLog.NestedDiagnosticsContext.GetAllMessages().Length; Assert.AreEqual(2, depth); var actualValue = a.GetLogger(this.GetType()).NestedThreadVariablesContext.Pop(); Assert.AreEqual("TestValue2", actualValue); actualValue = a.GetLogger(this.GetType()).NestedThreadVariablesContext.Pop(); Assert.AreEqual("TestValue1", actualValue); hasItems = a.GetLogger(this.GetType()).NestedThreadVariablesContext.HasItems; Assert.AreEqual(false, hasItems); depth = global::NLog.NestedDiagnosticsContext.GetAllMessages().Length; Assert.AreEqual(0, depth); }
public void CheckThreadVariablesSet() { var a = new NLogLoggerFactoryAdapter((Common.Logging.Configuration.NameValueCollection)null); a.GetLogger(this.GetType()).ThreadVariablesContext.Set("TestKey", "TestValue"); var actualValue = global::NLog.MappedDiagnosticsContext.Get("TestKey"); Assert.AreEqual("TestValue", actualValue); }
public void CheckGlobalVariablesSet() { var a = new NLogLoggerFactoryAdapter((Common.Logging.Configuration.NameValueCollection)null); var testValue = new object(); a.GetLogger(this.GetType()).GlobalVariablesContext.Set("TestKey", testValue); var actualValue = global::NLog.GlobalDiagnosticsContext.GetObject("TestKey"); Assert.AreEqual(testValue, actualValue); }
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>()); }