Ejemplo n.º 1
0
        public void LogWithRedirectionWorksWithExceptionMessage()
        {
            // --- Arrange
            if (!Directory.Exists(LOG_ROOT))
            {
                Directory.CreateDirectory(LOG_ROOT);
            }
            File.Delete(Path.Combine(LOG_ROOT, LOG_FILE));
            var tracer   = new FileTraceLogger(LOG_FILE, LOG_ROOT, flushAfter: 1);
            var eventLog = new EventLog(SEEMPLEST_LOG2);

            // --- Act
            WindowsEventLogger.RedirectLogTo(tracer);
            WindowsEventLogger.Log <SampleError>(new NullReferenceException());

            // --- Assert
            EventLog.Exists(SEEMPLEST_LOG2).ShouldBeFalse();
            eventLog.Dispose();

            var text  = File.ReadAllText(Path.Combine(LOG_ROOT, LOG_FILE));
            var lines = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            lines.ShouldHaveCountOf(3);
            var parts = lines[0].Split(new[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);

            parts[1].ShouldEqual("Error");
        }
Ejemplo n.º 2
0
        public void LogRedirectionConvertsTypesAsExpected()
        {
            // --- Arrange
            if (!Directory.Exists(LOG_ROOT))
            {
                Directory.CreateDirectory(LOG_ROOT);
            }
            File.Delete(Path.Combine(LOG_ROOT, LOG_FILE));
            var tracer   = new FileTraceLogger(LOG_FILE, LOG_ROOT, flushAfter: 1);
            var eventLog = new EventLog(SEEMPLEST_LOG2);

            // --- Act
            WindowsEventLogger.RedirectLogTo(tracer);
            WindowsEventLogger.Log <SampleError>();
            WindowsEventLogger.Log <SampleWarning>();
            WindowsEventLogger.Log <SampleInformation>();
            WindowsEventLogger.Log <SampleFailureAudit>();
            WindowsEventLogger.Log <SampleSuccessAudit>();

            // --- Assert
            EventLog.Exists(SEEMPLEST_LOG2).ShouldBeFalse();
            eventLog.Dispose();

            var text  = File.ReadAllText(Path.Combine(LOG_ROOT, LOG_FILE));
            var lines = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            lines.ShouldHaveCountOf(5);
            var expectedCats = new[] { "Error", "Warning", "Informational", "Error", "Success" };

            for (var i = 0; i < 5; i++)
            {
                var parts = lines[i].Split(new[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);
                parts[1].ShouldEqual(expectedCats[i]);
            }
        }
Ejemplo n.º 3
0
        public void LogWithRedirectionWorksAsExpected()
        {
            // --- Arrange
            if (!Directory.Exists(LOG_ROOT))
            {
                Directory.CreateDirectory(LOG_ROOT);
            }
            File.Delete(Path.Combine(LOG_ROOT, LOG_FILE));
            var tracer   = new FileTraceLogger(LOG_FILE, LOG_ROOT, flushAfter: 1);
            var eventLog = new EventLog(SEEMPLEST_LOG2);

            // --- Act
            WindowsEventLogger.RedirectLogTo(tracer);
            WindowsEventLogger.Log <WithStringNameAttribute>();

            // --- Assert
            EventLog.Exists(SEEMPLEST_LOG2).ShouldBeFalse();
            eventLog.Dispose();

            var text  = File.ReadAllText(Path.Combine(LOG_ROOT, LOG_FILE));
            var lines = text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            lines.ShouldHaveCountOf(1);
            var parts = lines[0].Split(new[] { "\t" }, StringSplitOptions.RemoveEmptyEntries);

            parts[1].ShouldEqual("Informational");
            parts[4].ShouldEqual("Windows Event Trace");
            parts[5].ShouldEqual("Default message");
            parts[6].ShouldEqual("EventId: 3, CategoryId: 5");
        }
Ejemplo n.º 4
0
        public void LogAfterResetWorksAsExpected()
        {
            // --- Arrange
            if (!Directory.Exists(LOG_ROOT))
            {
                Directory.CreateDirectory(LOG_ROOT);
            }
            File.Delete(Path.Combine(LOG_ROOT, LOG_FILE));
            var tracer   = new FileTraceLogger(LOG_FILE, LOG_ROOT, flushAfter: 1);
            var eventLog = new EventLog(SEEMPLEST_LOG2);

            WindowsEventLogger.RedirectLogTo(tracer);
            WindowsEventLogger.Log <WithStringNameAttribute>();

            // --- Act
            WindowsEventLogger.Reset();
            WindowsEventLogger.Log <WithStringNameAttribute>();

            // --- Assert
            var after      = eventLog.Entries;
            var afterCount = after.Count;

            afterCount.ShouldEqual(1);
            var lastentry = after[after.Count - 1];

            lastentry.Category.ShouldEqual("(5)");
            lastentry.InstanceId.ShouldEqual(3);
            lastentry.Message.ShouldEqual("Default message");
            lastentry.Source.ShouldEqual(SEEMPLEST_SOURCE);
            lastentry.EntryType.ShouldEqual(EventLogEntryType.Information);
            eventLog.Dispose();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Elindítja háttérben futó feldolgozásokat
 /// </summary>
 public static void StartBackgroundProcessing()
 {
     Tracer.Start();
     WindowsEventLogger.RedirectLogTo(Tracer.LoggerInstance);
     s_EmailProcessor.SetContext(new EmailTaskExecutionContext());
     s_EmailProcessor.Start();
 }