Inheritance: Common.Logging.Factory.AbstractCachingLoggerFactoryAdapter
        public void LoggingWithCustomEventSource()
        {
            var adapter = new ETWLoggerFactoryAdapter { EventSource = new CustomTestEventSource() };
            var logger = adapter.GetLogger(string.Empty);

            logger.Warn("This message should never appear in the ETW logs b/c its ignored by the custom EventSource for the sake of the test!");
        }
        public void LoggingWithException()
        {
            var adapter = new ETWLoggerFactoryAdapter();
            var logger = adapter.GetLogger(string.Empty);

            logger.Debug("This is a test message from ETW source!", new Exception("I am the test exception"));
        }
        public void BasicLoggingScenario()
        {
            var adapter = new ETWLoggerFactoryAdapter();
            var logger = adapter.GetLogger(string.Empty);

            logger.Warn("This is a test message from ETW source!");
        }
        public void CanSetDifferentEventSourceTypesOnMultipleAdapters()
        {
            var adapter1 = new ETWLoggerFactoryAdapter { EventSource = new TestEventSource1() };
            var adapter2 = new ETWLoggerFactoryAdapter { EventSource = new TestEventSource2() };

            Assert.That(adapter1.EventSource is TestEventSource1);
            Assert.That(adapter2.EventSource is TestEventSource2);
        }
        public void ByDefaultCannotSetEventSourceToSameTypeMultipleTimesOnSingleAdapter()
        {
            //setting the EventSource once is permitted
            var adapter = new ETWLoggerFactoryAdapter { EventSource = new TestEventSource3() };

            //setting it to another instance of the same type again is not
            Assert.Throws<InvalidOperationException>(() => adapter.EventSource = new TestEventSource3());
        }
        public void CanSetEventSourceToSameInstanceOfSameTypeMultipleTimes()
        {
            var eventSource = new TestEventSource4();
            var adapter = new ETWLoggerFactoryAdapter();

            //setting the event source to the same *instance* multiple times should not throw
            adapter.EventSource = eventSource;
            adapter.EventSource = eventSource;
        }
        public void CanUseDefaultEventSourceTypeIfNoneSpecifiedInConfigFile()
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
                <logging>
                  <factoryAdapter type='Common.Logging.ETW.ETWLoggerFactoryAdapter, Common.Logging.ETWLogger'>
                  </factoryAdapter>
                </logging>";
            var reader = new StandaloneConfigurationReader(xml);
            var setting = reader.GetSection(null) as LogSetting;


            Assume.That(setting, Is.Not.Null, "Failed to parse config to create expected LogSetting instance.");


            var adapter = new ETWLoggerFactoryAdapter(setting.Properties);

            Assert.That(adapter.EventSource, Is.TypeOf<CommonLoggingEventSource>());

        }
        public void CanSetEventSourceToSameTypeMultipleTimesOnSingleAdapterWithPermitDuplicateSetToTrue()
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
                <logging>
                  <factoryAdapter type='Common.Logging.ETW.ETWLoggerFactoryAdapter, Common.Logging.ETWLogger'>
                    <arg key='permitDuplicateEventSourceRegistration' value='true'/>
                  </factoryAdapter>
                </logging>";
            var reader = new StandaloneConfigurationReader(xml);
            var setting = reader.GetSection(null) as LogSetting;

            Assume.That(setting, Is.Not.Null, "Failed to parse config to create expected LogSetting instance.");


            var adapter = new ETWLoggerFactoryAdapter(setting.Properties);

            adapter.EventSource = new TestEventSource5();
            adapter.EventSource = new TestEventSource5();
        }
        public void CanReadLogLevelFromConfigFile()
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
                <logging>
                  <factoryAdapter type='Common.Logging.ETW.ETWLoggerFactoryAdapter, Common.Logging.ETWLogger'>
                    arg key='level' value='warn' />
                  </factoryAdapter>
                </logging>";
            var reader = new StandaloneConfigurationReader(xml);
            var setting = reader.GetSection(null) as LogSetting;


            Assume.That(setting, Is.Not.Null, "Failed to parse config to create expected LogSetting instance.");


            var adapter = new ETWLoggerFactoryAdapter(setting.Properties);

            Assert.That(adapter.LogLevel.HasFlag(LogLevel.Warn));

        }