Ejemplo n.º 1
0
        public void TraceWithTraceListenerReadsFromAppConfigAndReplacesDefaultListener()
        {
            var name = "TraceSourceWithDefaultListenerAndOtherListener";

            var defaultTraceListenerMock = new DefaultTraceListenerMock();
            var currentListener          = Logger.SetTraceListener(defaultTraceListenerMock);

            var result = Logger.Get(name);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Listeners);
            Assert.AreEqual(2, result.Listeners.Count);
            Assert.IsTrue
            (
                result.Listeners[0].GetType() == defaultTraceListenerMock.GetType() && result.Listeners[1].GetType() == typeof(TraceListenerMock)
                ||
                result.Listeners[1].GetType() == defaultTraceListenerMock.GetType() && result.Listeners[0].GetType() == typeof(TraceListenerMock)
            );

            // SourceLevel is set to error which is taken from the app.config,
            // even though the traceSource was created in code with SourceLevels.All
            Assert.AreEqual(SourceLevels.Error, result.Switch.Level);

            Logger.SetTraceListener(currentListener);
        }
Ejemplo n.º 2
0
        public void TraceWithTraceListenerReadsFromAppConfig()
        {
            var name = "TraceSourceWithOtherListener";

            var defaultTraceListenerMock = new DefaultTraceListenerMock();
            var currentListener          = Logger.SetTraceListener(defaultTraceListenerMock);

            var result = Logger.Get(name);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Listeners);
            Assert.AreEqual(1, result.Listeners.Count);
            Assert.IsInstanceOfType(result.Listeners[0], typeof(TraceListenerMock));

            // SourceLevel is set to error which is taken from the app.config,
            // even though the traceSource was created in code with SourceLevels.All
            Assert.AreEqual(SourceLevels.Error, result.Switch.Level);

            var ex = new ArgumentException("arbitrayExceptionMessage")
            {
                Source = "arbitrarySource",
            };

            result.TraceException(ex, "arbitraryMessage");

            Logger.SetTraceListener(currentListener);
        }
Ejemplo n.º 3
0
        public void SetDefaultTraceListenerSucceeds()
        {
            var name = Guid.NewGuid().ToString();

            var defaultTraceListenerMock = new DefaultTraceListenerMock();
            var currentListener          = Logger.SetTraceListener(defaultTraceListenerMock);

            var result = Logger.Get(name);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Listeners);
            Assert.AreEqual(1, result.Listeners.Count);
            Assert.IsInstanceOfType(result.Listeners[0], defaultTraceListenerMock.GetType());

            Logger.SetTraceListener(currentListener);
        }
Ejemplo n.º 4
0
        public void TraceWithTraceListener()
        {
            var name = string.Format("traceSource-{0}", Guid.NewGuid());

            var defaultTraceListenerMock = new DefaultTraceListenerMock();
            var currentListener          = Logger.SetTraceListener(defaultTraceListenerMock);

            var result = Logger.Get(name);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Listeners);
            Assert.AreEqual(1, result.Listeners.Count);
            Assert.IsInstanceOfType(result.Listeners[0], defaultTraceListenerMock.GetType());

            var ex = new ArgumentException("arbitrayExceptionMessage")
            {
                Source = "arbitrarySource",
            };

            result.TraceException(ex, "arbitraryMessage");

            Logger.SetTraceListener(currentListener);
        }