Beispiel #1
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());
        }
Beispiel #2
0
        public void Check1TraceInformation1TraceError1TraceWarningWithoutDelayed()
        {
            CleanOutput();

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

                try
                {
                    throw new Exception("Exception 1");
                }
                catch (Exception e)
                {
                    try
                    {
                        throw new Exception("Exception 2", e);
                    }
                    catch (Exception e1)
                    {
                        try
                        {
                            throw new Exception("Exception 3", e1);
                        }
                        catch (Exception e2)
                        {
                            try
                            {
                                throw new Exception("Exception 4", e2);
                            }
                            catch (Exception e3)
                            {
                                try
                                {
                                    throw new Exception("Exception 5", e3);
                                }
                                catch (Exception e4)
                                {
                                    AdvancedTrace.TraceError("MyError", e4, "Info");
                                }
                            }
                        }
                    }
                }

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

            var xmlDoc = new XmlDocument();

            xmlDoc.Load(Path.Combine(CurrentDirectory, "Working_session_1_1.xml"));
        }
Beispiel #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());
        }
Beispiel #4
0
        public void Check1TraceWarningWithoutDelayed()
        {
            CleanOutput();

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

                AdvancedTrace.RemoveTraceListener(AdvancedTrace.ListenerType.All, logStorage);
            }
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(Path.Combine(CurrentDirectory, "Working_session_1_1.xml"));
        }