Exemplo n.º 1
0
        public void ThrowsOnUnableToDetermineCustomCommonLoggingEventSourceType()
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
                <logging>
                  <factoryAdapter type='Common.Logging.ETW.ETWLoggerFactoryAdapter, Common.Logging.ETWLogger'>
                    <arg key='commonLoggingEventSourceType' value='I am not a type specification.'/>
                  </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.");
            Assert.Throws <ConfigurationException>(() => new ETWLoggerFactoryAdapter(setting.Properties));
        }
Exemplo n.º 2
0
        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>());
        }
Exemplo n.º 3
0
        public void CanSetEventSourceToSameTypeMultipleTimesOnMultipleAdapterWithPermitDuplicateSetToTrue()
        {
            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 adapter1 = new ETWLoggerFactoryAdapter(setting.Properties);
            var adapter2 = new ETWLoggerFactoryAdapter(setting.Properties);

            adapter1.EventSource = new TestEventSource5();
            adapter2.EventSource = new TestEventSource5();
        }
Exemplo n.º 4
0
        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));
        }
        public void CanReadCustomCommonLoggingEventSourceTypeFromConfigFile()
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
                <logging>
                  <factoryAdapter type='Common.Logging.ETW.ETWLoggerFactoryAdapter, Common.Logging.ETWLogger'>
                    <arg key='commonLoggingEventSourceType' value='Common.Logging.ETWLogger.Tests.MyCustomEventSource,Common.Logging.ETWLogger.Tests'/>
                  </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.ETWEventSource, Is.TypeOf <MyCustomEventSource>());
        }
        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));

        }
        public void ThrowsOnCustomCommonLoggingEventSourceTypeIsWrongType()
        {
            const string xml =
                @"<?xml version='1.0' encoding='UTF-8' ?>
                <logging>
                  <factoryAdapter type='Common.Logging.ETW.ETWLoggerFactoryAdapter, Common.Logging.ETWLogger'>
                    <arg key='commonLoggingEventSourceType' value='Common.Logging.ETW.ETWLogger,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.");
            Assert.Throws<ConfigurationException>(() => new ETWLoggerFactoryAdapter(setting.Properties));
        }