public static void TestIt()
        {
            string listened = null;
            DelegateTraceListener listener = new DelegateTraceListener("Test Listener", (string message) => { listened = message; });

            listener.Write(1);
            Assert.That(listened, Is.Null, "The listener should buffer until a new line is received.");

            listener.WriteLine(String.Empty);
            Assert.That(listened, Is.EqualTo("1" + Environment.NewLine), "The buffer should be emptied as soon as a New Line is received.");

            listener.Write("Hello" + Environment.NewLine + "New World");
            Assert.That(listened, Is.EqualTo("Hello" + Environment.NewLine), "The buffer should contain text up to the last new line but not more.");
        }
예제 #2
0
        private void MainForm_Load(Object sender, EventArgs e)
        {
            // configure delegate trace listener
            DelegateTraceListener traceListener = new DelegateTraceListener();

            traceListener.WriteDelegate     += traceListener_WriteDelegate;
            traceListener.WriteLineDelegate += traceListener_WriteDelegate;
            Trace.Listeners.Add(traceListener);

            // and the timer to flush messages to the message box
            traceDelegate  = traceToMessageBox;
            timer          = new Timer();
            timer.Interval = 1000;
            timer.Tick    += timer_Tick;
            timer.Start();
        }
예제 #3
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // bind connection strings to the dropdown list
            cboConnectionString.DisplayMember = "Name";
            foreach (ConnectionStringSettings connectionStringSetting in ConfigurationManager.ConnectionStrings)
            {
                cboConnectionString.Items.Add(connectionStringSetting);
            }

            if (cboConnectionString.Items.Count > 0)
            {
                cboConnectionString.SelectedIndex = 0;
            }

            // configure delegate trace listener
            DelegateTraceListener traceListener = new DelegateTraceListener();

            traceDelegate = new TraceHandler(traceToMessageBox);
            traceListener.WriteDelegate     += new DelegateTraceListener.WriteHandler(traceListener_WriteDelegate);
            traceListener.WriteLineDelegate += new DelegateTraceListener.WriteHandler(traceListener_WriteLineDelegate);
            Trace.Listeners.Add(traceListener);
        }
예제 #4
0
파일: MainForm.cs 프로젝트: jjg0519/OA
        private void MainForm_Load(Object sender, EventArgs e)
        {
            // bind connection Strings to the dropdown lists
            cboPersistenceService.DisplayMember = "Name";
            cboTrackingService.DisplayMember    = "Name";
            foreach (ConnectionStringSettings connectionStringSetting in ConfigurationManager.ConnectionStrings)
            {
                cboPersistenceService.Items.Add(connectionStringSetting);
                cboTrackingService.Items.Add(connectionStringSetting);
            }

            cboTrackingService.Items.Insert(0, "None");

            if (cboPersistenceService.Items.Count > 0)
            {
                cboPersistenceService.SelectedIndex = 0;
            }

            if (cboTrackingService.Items.Count > 0)
            {
                cboTrackingService.SelectedIndex = 0;
            }

            // configure delegate trace listener
            DelegateTraceListener traceListener = new DelegateTraceListener();

            traceListener.WriteDelegate     += traceListener_WriteDelegate;
            traceListener.WriteLineDelegate += traceListener_WriteDelegate;
            Trace.Listeners.Add(traceListener);

            // and the timer to flush messages to the message box
            traceDelegate  = traceToMessageBox;
            timer          = new Timer();
            timer.Interval = 1000;
            timer.Tick    += timer_Tick;
            timer.Start();
        }
예제 #5
0
        public static void TestLoggingListenerAndLevels()
        {
            string listenerMessage = null;

            DelegateTraceListener traceListener = new DelegateTraceListener("AxCryptTestListener", (string message) =>
            {
                listenerMessage = (listenerMessage ?? String.Empty) + message;
            });

            Trace.Listeners.Add(traceListener);
            try
            {
                Resolve.Log.SetLevel(LogLevel.Fatal);

                listenerMessage = null;
                Resolve.Log.LogDebug("Verbose" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is off, Verbose logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogInfo("Info" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is off, Info logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogWarning("Warning" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is off, Warning logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogError("Error" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is off, Error logging should not generate a message.");

                Resolve.Log.SetLevel(LogLevel.Error);

                listenerMessage = null;
                Resolve.Log.LogDebug("Verbose" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is Error, Verbose logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogInfo("Info" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is Error, Info logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogWarning("Warning" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is Error, Warning logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogFatal("Fatal" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Fatal"), "When logging is Error, Fatal logging should generate a message.");

                listenerMessage = null;
                Resolve.Log.LogError("Error" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Error"), "When logging is Error, Error logging should generate a message.");

                Resolve.Log.SetLevel(LogLevel.Warning);

                listenerMessage = null;
                Resolve.Log.LogDebug("Verbose" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is Warning, Verbose logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogInfo("Info" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is Warning, Info logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogWarning("Warning" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Warning"), "When logging is Warning, Warning logging should generate a message.");

                listenerMessage = null;
                Resolve.Log.LogError("Error" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Error"), "When logging is Warning, Error logging should generate a message.");

                Resolve.Log.SetLevel(LogLevel.Info);

                listenerMessage = null;
                Resolve.Log.LogDebug("Verbose" + Environment.NewLine);
                Assert.That(listenerMessage, Is.EqualTo(null), "When logging is Info, Verbose logging should not generate a message.");

                listenerMessage = null;
                Resolve.Log.LogInfo("Info" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Info"), "When logging is Info, Info logging should generate a message.");

                listenerMessage = null;
                Resolve.Log.LogWarning("Warning" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Warning"), "When logging is Info, Warning logging should generate a message.");

                listenerMessage = null;
                Resolve.Log.LogError("Error" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Error"), "When logging is Info, Error logging should generate a message.");

                Resolve.Log.SetLevel(LogLevel.Debug);

                listenerMessage = null;
                Resolve.Log.LogDebug("Verbose" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Verbose"), "When logging is Verbose, Verbose logging should generate a message.");

                listenerMessage = null;
                Resolve.Log.LogInfo("Info" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Info"), "When logging is Verbose, Info logging should generate a message.");

                listenerMessage = null;
                Resolve.Log.LogWarning("Warning" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Warning"), "When logging is Verbose, Warning logging should generate a message.");

                listenerMessage = null;
                Resolve.Log.LogError("Error" + Environment.NewLine);
                Assert.That(listenerMessage.Contains("Error"), "When logging is Verbose, Error logging should generate a message.");
            }
            finally
            {
                Trace.Listeners.Remove(traceListener);
            }
        }