Example #1
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();
        }
Example #2
0
        public void TestInit()
        {
            if (EventLog.Exists(SEEMPLEST_LOG))
            {
                EventLog.Delete(SEEMPLEST_LOG);
            }
            if (EventLog.Exists(SEEMPLEST_LOG2))
            {
                EventLog.Delete(SEEMPLEST_LOG2);
            }
            var configSettings = new AppConfigurationSettings(typeof(AppConfigProvider));

            AppConfigurationManager.Configure(configSettings);
            WindowsEventLogger.LogSourceMapper = new DefaultLogSourceNameMapper();
            WindowsEventLogger.Reset();
        }