Esempio n. 1
0
        public void Check1TraceErrorWithoutDelayed()
        {
            CleanOutput();

            using (var logStorage = new XmlWriterTraceListener("Application 1", AppDomain.CurrentDomain.BaseDirectory, 2, false))
            {
                AdvancedTrace.AddTraceListener(AdvancedTrace.ListenerType.All, logStorage);

                try
                {
                    throw new Exception("Exception 1");
                }
                catch (Exception e)
                {
                    try
                    {
                        throw new Exception("Exception 2", e);
                    }
                    catch (Exception e1)
                    {
                        AdvancedTrace.TraceError("MyError", e1, "Info");
                    }
                }

                AdvancedTrace.RemoveTraceListener(AdvancedTrace.ListenerType.All, logStorage);
            }

            var xmlDoc = new XmlDocument();

            xmlDoc.Load(Path.Combine(CurrentDirectory, "Working_session_1_1.xml"));
        }
Esempio n. 2
0
        public void TraceAllWithNewType()
        {
            const string newType = "__NEW_TYPE__";

            var listener    = new TestListener();
            var advListener = new TestAdvancedTraceListener();

            AdvancedTrace.AddTraceListener(AdvancedTrace.ListenerType.All, listener);
            AdvancedTrace.AddTraceListener(AdvancedTrace.ListenerType.All, advListener);
            AdvancedTrace.AddTraceType(newType);

            AdvancedTrace.TraceInformation("Default information");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceInformation("Information with exception", new FileNotFoundException("file.ext"));
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceInformation("Information on a category", "Category2");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceInformation("Information with exception on a category", new Exception("Base exception"), "Category1");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());

            AdvancedTrace.TraceDatabase("Database");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceError("Error");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceFatal("Fatal");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceDebug("Debug");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceSQL("SQL");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceProblem("Problem");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceWarning("Warning");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());


            AdvancedTrace.Trace(newType, "New type");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());

            AdvancedTrace.TraceInformation("Finish");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
        }
Esempio n. 3
0
        public void MultipleTrace()
        {
            var listener    = new TestListener();
            var advListener = new TestAdvancedTraceListener();

            AdvancedTrace.AddTraceListener(AdvancedTrace.ListenerType.Information, listener);
            AdvancedTrace.AddTraceListener(AdvancedTrace.ListenerType.Warning, listener);
            AdvancedTrace.AddTraceListener(AdvancedTrace.ListenerType.Information, advListener);
            AdvancedTrace.AddTraceListener(AdvancedTrace.ListenerType.Problem, advListener);

            AdvancedTrace.TraceInformation("Default information");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceInformation("Information with exception", new FileNotFoundException("file.ext"));
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceInformation("Information on a category", "Category2");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceInformation("Information with exception on a category", new Exception("Base exception"), "Category1");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());

            AdvancedTrace.TraceDatabase("Database");
            Assert.False(listener.IsNewMessage());
            Assert.False(advListener.IsNewMessage());
            AdvancedTrace.TraceError("Error");
            Assert.False(listener.IsNewMessage());
            Assert.False(advListener.IsNewMessage());
            AdvancedTrace.TraceFatal("Fatal");
            Assert.False(listener.IsNewMessage());
            Assert.False(advListener.IsNewMessage());
            AdvancedTrace.TraceDebug("Debug");
            Assert.False(listener.IsNewMessage());
            Assert.False(advListener.IsNewMessage());
            AdvancedTrace.TraceSQL("SQL");
            Assert.False(listener.IsNewMessage());
            Assert.False(advListener.IsNewMessage());
            AdvancedTrace.TraceProblem("Problem");
            Assert.False(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
            AdvancedTrace.TraceWarning("Warning");
            Assert.True(listener.IsNewMessage());
            Assert.False(advListener.IsNewMessage());

            AdvancedTrace.TraceInformation("Finish");
            Assert.True(listener.IsNewMessage());
            Assert.True(advListener.IsNewMessage());
        }