Example #1
0
        public void ActivatingAppenderOptionsWillChangeEventSourceIfNecessary()
        {
            const string source = "Be.Stateless.Logging.EventSourceFromOtherEventLog";

            try
            {
                if (EventLog.SourceExists(source))
                {
                    EventLog.DeleteEventSource(source, MACHINE_NAME);
                }

                EventLog.CreateEventSource(new EventSourceCreationData(source, "System"));
                var logName = EventLog.LogNameFromSourceName(source, MACHINE_NAME);
                Assert.That(logName, Is.EqualTo("System"));

                var appender = new EventLogAppender {
                    ApplicationName = source
                };
                appender.ActivateOptions();

                logName = EventLog.LogNameFromSourceName(source, MACHINE_NAME);
                Assert.That(logName, Is.EqualTo(APPLICATION_LOG_NAME));
            }
            finally
            {
                EventLog.DeleteEventSource(source, MACHINE_NAME);
            }
        }
Example #2
0
        public void LogErrorEvent()
        {
            var message = Guid.NewGuid().ToString();

            var exception = new ArgumentNullException();

            try
            {
                throw exception;
            }
            catch (Exception ex)
            {
                _logger.Error(message, ex);
            }

            var le = ApplicationEventLog.First(message);

            Assert.That(le.CategoryNumber, Is.EqualTo((short)LevelCategory.Error));
            Assert.That(le.InstanceId, Is.EqualTo(EventLogAppender.TypeHashAlgorithm(exception.GetType())));
            Assert.That(le.Source, Is.EqualTo(TEST_SOURCE));
        }