public void SetUp()
        {
            AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);

            logWriter =
#if NETCOREAPP
                new LogWriterFactory(NetCoreHelper.LookupConfigSection).Create();
#else
                new LogWriterFactory().Create();
#endif
            MockTraceListener.Reset();
            ErrorsMockTraceListener.Reset();

            emptyTraceSource = new LogSource("none", Enumerable.Empty <TraceListener>(), SourceLevels.All);
            Assert.IsFalse(emptyTraceSource.Listeners.Any());
        }
        public void UseTracingWithDisabledLoggerDoesntWrite()
        {
            MockTraceListener.Reset();

            LogSource source = new LogSource("tracesource", new[] { new MockTraceListener() }, SourceLevels.All);

            List <LogSource> traceSources = new List <LogSource>(new LogSource[] { source });
            LogWriter        logWriter    = new LogWriter(new List <ILogFilter>(), new List <LogSource>(), source, null, new LogSource("errors"), "default", false, false);

            using (Tracer tracer = new Tracer("testoperation", logWriter))
            {
                Assert.AreEqual(0, MockTraceListener.Entries.Count);
            }

            Assert.AreEqual(0, MockTraceListener.Entries.Count);
        }
        [TestMethod] //misterious build fail on commandline runner
        public void UsingTracerWritesEntryAndExitMessages()
        {
            MockTraceListener.Reset();
            Guid currentActivityId = Guid.Empty;

            using (new Tracer(operation))
            {
                currentActivityId = Trace.CorrelationManager.ActivityId;
                Assert.AreEqual(1, MockTraceListener.Entries.Count);
                AssertLogEntryIsValid(MockTraceListener.LastEntry, Tracer.startTitle, operation, currentActivityId, true);
                MockTraceListener.Reset();
            }

            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            AssertLogEntryIsValid(MockTraceListener.LastEntry, Tracer.endTitle, operation, currentActivityId, false);
        }
        public void GetTracerFromTraceManagerWithNoInstrumentation()
        {
            MockTraceListener.Reset();
            LogSource source = new LogSource("tracesource", SourceLevels.All);

            source.Listeners.Add(new MockTraceListener());
            List <LogSource> traceSources = new List <LogSource>(new LogSource[] { source });
            LogWriter        lg           = new LogWriter(new List <ILogFilter>(), new List <LogSource>(), source, null, new LogSource("errors"), "default", true, false);
            TraceManager     tm           = new TraceManager(lg);

            Assert.IsNotNull(tm);
            using (tm.StartTrace("testoperation"))
            {
                Assert.AreEqual(1, MockTraceListener.Entries.Count);
            }
            Assert.AreEqual(2, MockTraceListener.Entries.Count);
        }
예제 #5
0
        public void ConfigurationChangeNotificationRefreshesLogger()
        {
            SystemConfigurationSource.ResetImplementation(false);
            Logger.Reset();
            MockTraceListener.Reset();
            Logger.Write("test", "MockCategoryOne");
            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            LoggingSettings rwSettings = rwConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings;

            ((CategoryFilterData)rwSettings.LogFilters.Get("Category")).CategoryFilters.Add(new CategoryFilterEntry("MockCategoryOne"));
            rwConfiguration.Save();
            SystemConfigurationSource.Implementation.ConfigSourceChanged(string.Empty);
            MockTraceListener.Reset();
            Logger.Write("test", "MockCategoryOne");
            Assert.AreEqual(0, MockTraceListener.Entries.Count, "should have been filtered out by the new category filter");
        }
예제 #6
0
        public void UsingTracerDoesNotWriteWhenDisabled()
        {
            using (new ContainerSwitcher(GetContainerWithTracingFlag(false), true))
            {
                MockTraceListener.Reset();
                Guid currentActivityId = Guid.Empty;

                using (new Tracer(operation))
                {
                    currentActivityId = Trace.CorrelationManager.ActivityId;
                    Assert.AreEqual(0, MockTraceListener.Entries.Count);
                }

                Assert.AreEqual(0, MockTraceListener.Entries.Count);
            }
            Logger.Reset();
        }
예제 #7
0
        public void UseTracingWithOwnLogWriter()
        {
            MockTraceListener.Reset();

            LogSource source = new LogSource("tracesource", SourceLevels.All);

            source.Listeners.Add(new MockTraceListener());

            List <LogSource> traceSources = new List <LogSource>(new LogSource[] { source });
            LogWriter        logWriter    = new LogWriter(new List <ILogFilter>(), new List <LogSource>(), source, null, new LogSource("errors"), "default", true, false);

            using (Tracer tracer = new Tracer("testoperation", logWriter, null))
            {
                Assert.AreEqual(1, MockTraceListener.Entries.Count);
            }

            Assert.AreEqual(2, MockTraceListener.Entries.Count);
        }
        public void EmptyCategoriesRevertToDefaultCategory()
        {
            MockTraceListener.Reset();
            LoggingSettings settings = LoggingSettings.GetLoggingSettings(new SystemConfigurationSource());

            LogEntry log = new LogEntry();

            log.EventId    = 1;
            log.Message    = "test";
            log.Categories = new string[0];
            log.Severity   = TraceEventType.Error;
            Logger.Write(log);

            Assert.IsNotNull(MockTraceListener.LastEntry);
            Assert.AreEqual("test", MockTraceListener.LastEntry.Message);
            Assert.AreEqual(1, MockTraceListener.LastEntry.Categories.Count);
            Assert.IsTrue(MockTraceListener.LastEntry.Categories.Contains(settings.DefaultCategory));
        }
예제 #9
0
        public void ConfigurationChangeNotificationRefreshesLoggerAutomatically()
        {
            ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(100);
            SystemConfigurationSource.ResetImplementation(true);
            Logger.Reset();
            MockTraceListener.Reset();
            Logger.Write("test", "MockCategoryOne");
            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            LoggingSettings rwSettings = rwConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings;

            ((CategoryFilterData)rwSettings.LogFilters.Get("Category")).CategoryFilters.Add(new CategoryFilterEntry("MockCategoryOne"));
            rwConfiguration.Save();
            Thread.Sleep(400);
            MockTraceListener.Reset();
            Logger.Write("test", "MockCategoryOne");
            Assert.AreEqual(0, MockTraceListener.Entries.Count);
        }
예제 #10
0
        public void Setup()
        {
            MockTraceListener.Reset();
            this.traceListener = new MockTraceListener();

            var logWriter =
                new LogWriter(
                    new ILogFilter[0],
                    new LogSource[0],
                    new LogSource("all", new TraceListener[] { traceListener }, SourceLevels.All),
                    new LogSource("not processed"),
                    new LogSource("errors"),
                    "default",
                    true,
                    false);

            Logger.SetLogWriter(logWriter, false);
        }
        public void LoggedExceptionCopiesExceptionDataForStringKeys()
        {
            MockTraceListener.Reset();
            Exception exception = new Exception("TEST EXCEPTION");
            object    value     = new object();
            object    key4      = new object();

            exception.Data.Add("key1", value);
            exception.Data.Add("key2", "value");
            exception.Data.Add("key3", 3);
            exception.Data.Add(key4, "value");
            Assert.IsFalse(ExceptionPolicy.HandleException(exception, "Logging Policy"));
            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            Assert.AreEqual(3, MockTraceListener.Entries[0].ExtendedProperties.Count);
            Assert.AreEqual(value, MockTraceListener.Entries[0].ExtendedProperties["key1"]);
            Assert.AreEqual("value", MockTraceListener.Entries[0].ExtendedProperties["key2"]);
            Assert.AreEqual(3, MockTraceListener.Entries[0].ExtendedProperties["key3"]);
        }
        public void LoggingHandlerCreatesFormatterWithTheDocumentedConstructor()
        {
            MockTraceListener.Reset();
            ConstructorSensingExceptionFormatter.Instances.Clear();
            Exception exception = new Exception("test exception");
            Guid      testGuid  = Guid.NewGuid();
            LoggingExceptionHandler handler
                = new LoggingExceptionHandler(
                      "TestCat",
                      0,
                      TraceEventType.Warning,
                      "test",
                      0,
                      typeof(ConstructorSensingExceptionFormatter),
                      Logger.Writer);

            handler.HandleException(exception, testGuid);
            Assert.AreEqual(1, ConstructorSensingExceptionFormatter.Instances.Count);
            Assert.AreSame(exception, ConstructorSensingExceptionFormatter.Instances[0].Exception);
            Assert.AreEqual(testGuid, ConstructorSensingExceptionFormatter.Instances[0].HandlingInstanceId);
        }
예제 #13
0
        public void UsingTracerDoesNotWriteWhenDisabled()
        {
            SystemConfigurationSource.ResetImplementation(false);

            //turn tracing off
            SetTracingFlag(false);

            MockTraceListener.Reset();
            Guid currentActivityId = Guid.Empty;

            using (new Tracer(operation))
            {
                currentActivityId = Trace.CorrelationManager.ActivityId;
                Assert.AreEqual(0, MockTraceListener.Entries.Count);
            }

            Assert.AreEqual(0, MockTraceListener.Entries.Count);

            //turn tracing back on
            SetTracingFlag(true);
        }
예제 #14
0
        public void LoggedMessagesDuringTracerAddsCategoryIds()
        {
            MockTraceListener.Reset();

            using (new Tracer(operation))
            {
                Assert.AreEqual(1, MockTraceListener.Entries.Count);
                Assert.AreEqual(1, MockTraceListener.LastEntry.Categories.Count);
                Assert.IsTrue(MockTraceListener.LastEntry.Categories.Contains(operation));
                MockTraceListener.Reset();

                Logger.Write("message", category);
                Assert.AreEqual(1, MockTraceListener.Entries.Count);
                Assert.AreEqual(2, MockTraceListener.LastEntry.Categories.Count);
                Assert.IsTrue(MockTraceListener.LastEntry.Categories.Contains(operation));
                Assert.IsTrue(MockTraceListener.LastEntry.Categories.Contains(category));
                MockTraceListener.Reset();
            }
            Assert.AreEqual(1, MockTraceListener.Entries.Count);
            Assert.AreEqual(1, MockTraceListener.LastEntry.Categories.Count);
            Assert.IsTrue(MockTraceListener.LastEntry.Categories.Contains(operation));
        }
        public void MultipleRequestsUseSameLogWriterInstance()
        {
            MockTraceListener.Reset();

            {
                ExceptionPolicyImpl policy = container.Resolve <ExceptionPolicyImpl>("Logging Policy");
                Assert.IsFalse(policy.HandleException(new Exception("TEST EXCEPTION")));
            }
            {
                ExceptionPolicyImpl policy = container.Resolve <ExceptionPolicyImpl>("Logging Policy");
                Assert.IsFalse(policy.HandleException(new Exception("TEST EXCEPTION")));
            }
            {
                ExceptionPolicyImpl policy = container.Resolve <ExceptionPolicyImpl>("Logging Policy");
                Assert.IsFalse(policy.HandleException(new Exception("TEST EXCEPTION")));
            }

            Assert.AreEqual(3, MockTraceListener.Entries.Count);
            Assert.AreEqual(3, MockTraceListener.Instances.Count);
            Assert.AreSame(MockTraceListener.Instances[0], MockTraceListener.Instances[1]);
            Assert.AreSame(MockTraceListener.Instances[0], MockTraceListener.Instances[2]);
        }
예제 #16
0
        public void NonStringElementsInLogicalOperationStackAreIgnored()
        {
            SetTracingFlag(true);
            MockTraceListener.Reset();
            Guid   currentActivityId         = Guid.Empty;
            object nonStringLogicalOperation = new object();
            object stringLogicalOperation    = "another operation";
            object nullLogicalOperation      = null;

            try
            {
                Trace.CorrelationManager.LogicalOperationStack.Push(nonStringLogicalOperation);
                Trace.CorrelationManager.LogicalOperationStack.Push(stringLogicalOperation);
                Trace.CorrelationManager.LogicalOperationStack.Push(nullLogicalOperation);

                using (new Tracer(operation))
                {
                    currentActivityId = Trace.CorrelationManager.ActivityId;
                    Assert.AreEqual(1, MockTraceListener.Entries.Count);
                }
            }
            finally
            {
                Trace.CorrelationManager.LogicalOperationStack.Pop();
                Trace.CorrelationManager.LogicalOperationStack.Pop();
                Trace.CorrelationManager.LogicalOperationStack.Pop();
            }

            Assert.AreEqual(2, MockTraceListener.Entries.Count);

            LogEntry logEntry = MockTraceListener.LastEntry;

            Assert.AreEqual(2, logEntry.Categories.Count);
            Assert.IsTrue(logEntry.Categories.Contains(operation));
            Assert.IsTrue(logEntry.Categories.Contains((string)stringLogicalOperation));
        }
 public void Teardown()
 {
     Logger.FlushContextItems();
     MockTraceListener.Reset();
 }
 public void SetUp()
 {
     AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
     Logger.SetLogWriter(new LogWriterFactory().Create(), false);
     MockTraceListener.Reset();
 }
 public void TearDown()
 {
     Logger.Reset();
     MockTraceListener.Reset();
 }
 public void SetUp()
 {
     Logger.Reset();
     MockTraceListener.Reset();
 }
 public void TearDown()
 {
     MockTraceListener.Reset();
     ErrorsMockTraceListener.Reset();
     logWriter.Dispose();
 }
 public void TearDown()
 {
     MockTraceListener.Reset();
     ErrorsMockTraceListener.Reset();
 }
예제 #23
0
 public void TearDown()
 {
     CommonUtil.DeletePrivateTestQ();
     MockTraceListener.Reset();
 }
예제 #24
0
 public void SetUp()
 {
     Logger.Reset();
     MockTraceListener.Reset();
     log = new LogEntry();
 }
 public void SetUp()
 {
     Logger.SetLogWriter(new LogWriterFactory().Create(), false);
     MockTraceListener.Reset();
     log = new LogEntry();
 }
예제 #26
0
 public void SetUp()
 {
     AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
     Logger.Reset();
     MockTraceListener.Reset();
 }