Esempio n. 1
0
        public void CriticalTestWithThrownExceptionOnly()
        {
            var log      = new TraceLog <GenericEventId>("tracelogTestSource");
            var listener = log.TraceSource.Listeners.OfType <TestTraceListener>().First();

            listener.MethodCallInformation.Clear();

            try
            {
                throw new ApplicationException("a0");
            }
            catch (Exception ex)
            {
                log.Critical(GenericEventId.AuthenticationCriticalError, ex);
            }

            var events = listener.MethodCallInformation;

            Assert.AreEqual(TraceEventType.Critical, events[0].EventType);
            Assert.AreEqual("tracelogTestSource", events[0].Source);
            Assert.AreEqual(9300, events[0].Id);

            Console.WriteLine(events[0].Message);
            var expectedMessageWithStartOfStackTrace = "Exception: System.ApplicationException: a0\r\n   at Essential.Diagnostics.Abstractions.Tests.TraceLogTests.CriticalTestWithThrownExceptionOnly() ";

            StringAssert.StartsWith(events[0].Message, expectedMessageWithStartOfStackTrace);
        }
Esempio n. 2
0
        public void CriticalTestFormatAndArgs()
        {
            var log      = new TraceLog <GenericEventId>("tracelogTestSource");
            var listener = log.TraceSource.Listeners.OfType <TestTraceListener>().First();

            listener.MethodCallInformation.Clear();

            log.Critical(GenericEventId.ConfigurationCriticalError, "c{0}", 1);

            var events = listener.MethodCallInformation;

            Assert.AreEqual(TraceEventType.Critical, events[0].EventType);
            Assert.AreEqual(9000, events[0].Id);
            StringAssert.StartsWith(events[0].Message, "c1");
        }
Esempio n. 3
0
        public void CriticalTestWithExceptionAndFormatAndArgs()
        {
            var log      = new TraceLog <GenericEventId>("tracelogTestSource");
            var listener = log.TraceSource.Listeners.OfType <TestTraceListener>().First();

            listener.MethodCallInformation.Clear();

            var ex = new ApplicationException("a2");

            log.Critical(GenericEventId.ConnectionCriticalError, ex, "b{0}", 1);

            var events = listener.MethodCallInformation;

            Assert.AreEqual(TraceEventType.Critical, events[0].EventType);
            Assert.AreEqual("tracelogTestSource", events[0].Source);
            Assert.AreEqual(9200, events[0].Id);

            Console.WriteLine(events[0].Message);
            var expectedMessageWithInsertedArgs = "b1|Exception: System.ApplicationException: a2";

            StringAssert.StartsWith(events[0].Message, expectedMessageWithInsertedArgs);
        }