當前位置: 首頁>>代碼示例>>C#>>正文


C# Configuration.LoggingSettings類代碼示例

本文整理匯總了C#中Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings的典型用法代碼示例。如果您正苦於以下問題:C# LoggingSettings類的具體用法?C# LoggingSettings怎麽用?C# LoggingSettings使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LoggingSettings類屬於Microsoft.Practices.EnterpriseLibrary.Logging.Configuration命名空間,在下文中一共展示了LoggingSettings類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Arrange

        protected override void Arrange()
        {
            base.Arrange();

            IConfigurationSource source = new DictionaryConfigurationSource();
            ConfigurationSourceBuilder sourceBuiler = new ConfigurationSourceBuilder();

            sourceBuiler.ConfigureLogging()
                .WithOptions.DisableTracing()
                .DoNotRevertImpersonation()
                .FilterOnPriority("prio filter").StartingWithPriority(10)
                .FilterOnCategory("categoryFiler").AllowAllCategoriesExcept("cat1")
                .LogToCategoryNamed("General")
                .SendTo.EventLog("Event Log Listener")
                .FormatWith(new FormatterBuilder().TextFormatterNamed("Default"))
                .LogToCategoryNamed("Critical")
                .SendTo.SharedListenerNamed("Event Log Listener")
                .SendTo.Custom<MyCustomListener>("Custom Listener")
                .SendTo.Email("Email Listener")
                .SendTo.SystemDiagnosticsListener("system diagnostics")
                .LogToCategoryNamed("msmq")
                .SendTo.Msmq("msmq");

            sourceBuiler.UpdateConfigurationWithReplace(source);
            LoggingSection = (LoggingSettings)source.GetSection(LoggingSettings.SectionName);
        }
開發者ID:HondaBey,項目名稱:EnterpriseLibrary6,代碼行數:26,代碼來源:LoggingConfigurationContext.cs

示例2: ValidateLoggingSettings

		private void ValidateLoggingSettings(LoggingSettings loggingSettings)
		{
			if (loggingSettings == null)
			{
				throw new System.Configuration.ConfigurationErrorsException(Resources.ExceptionLoggingSectionNotFound);
			}
		}
開發者ID:wuyingyou,項目名稱:uniframework,代碼行數:7,代碼來源:LogWriterStructureHolderCustomFactory.cs

示例3: CanDeserializeSerializedConfiguration

		public void CanDeserializeSerializedConfiguration()
		{
			string name = "name";
			string write = "write";
			string add = "add";
			string database = "database";
			string formatter = "formatter";

			TraceListenerData data = new FormattedDatabaseTraceListenerData(name, write, add, database, formatter, TraceOptions.Callstack);

			LoggingSettings settings = new LoggingSettings();
			settings.TraceListeners.Add(data);

			IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
			sections[LoggingSettings.SectionName] = settings;
			IConfigurationSource configurationSource
				= ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

			LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

			Assert.AreEqual(1, roSettigs.TraceListeners.Count);
			Assert.IsNotNull(roSettigs.TraceListeners.Get(name));
			Assert.AreEqual(TraceOptions.Callstack, roSettigs.TraceListeners.Get(name).TraceOutputOptions);
			Assert.AreSame(typeof(FormattedDatabaseTraceListenerData), roSettigs.TraceListeners.Get(name).GetType());
			Assert.AreSame(typeof(FormattedDatabaseTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType);
			Assert.AreSame(typeof(FormattedDatabaseTraceListener), roSettigs.TraceListeners.Get(name).Type);
			Assert.AreEqual(add, ((FormattedDatabaseTraceListenerData)roSettigs.TraceListeners.Get(name)).AddCategoryStoredProcName);
			Assert.AreEqual(database, ((FormattedDatabaseTraceListenerData)roSettigs.TraceListeners.Get(name)).DatabaseInstanceName);
			Assert.AreEqual(formatter, ((FormattedDatabaseTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter);
			Assert.AreEqual(write, ((FormattedDatabaseTraceListenerData)roSettigs.TraceListeners.Get(name)).WriteLogStoredProcName);
		}
開發者ID:ChiangHanLung,項目名稱:PIC_VDS,代碼行數:31,代碼來源:FormattedDatabaseTraceListenerConfigurationFixture.cs

示例4: Arrange

        protected override void Arrange()
        {
            base.Arrange();

            var builder = new ConfigurationSourceBuilder();
            builder.ConfigureLogging()
                        .LogToCategoryNamed("category")
                            .SendTo
                                .EventLog("listener")
                        .SpecialSources
                            .AllEventsCategory
                                .SendTo
                                    .EventLog("listener")
                        .SpecialSources
                            .LoggingErrorsAndWarningsCategory
                                .SendTo
                                    .EventLog("listener")
                        .SpecialSources
                            .UnprocessedCategory
                                .SendTo
                                    .EventLog("listener");


            var source = new DictionaryConfigurationSource();
            builder.UpdateConfigurationWithReplace(source);

            ElementLookup = Container.Resolve<ElementLookup>();
            LoggingSection = (LoggingSettings)source.GetSection(LoggingSettings.SectionName);
        }
開發者ID:jmeckley,項目名稱:Enterprise-Library-5.0,代碼行數:29,代碼來源:when_adding_a_new_element.cs

示例5: CanDeserializeSerializedConfiguration

        public void CanDeserializeSerializedConfiguration()
        {
            string name = "name";
            string source = "source";
            string log = "log";
            string machine = "machine";
            string formatter = "formatter";

            TraceListenerData data = new FormattedEventLogTraceListenerData(name, source, log, machine,
                                                                            formatter, TraceOptions.Callstack);

            LoggingSettings settings = new LoggingSettings();
            settings.TraceListeners.Add(data);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[LoggingSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(1, roSettigs.TraceListeners.Count);
            Assert.IsNotNull(roSettigs.TraceListeners.Get(name));
            Assert.AreEqual(TraceOptions.Callstack, roSettigs.TraceListeners.Get(name).TraceOutputOptions);
            Assert.AreSame(typeof(FormattedEventLogTraceListenerData), roSettigs.TraceListeners.Get(name).GetType());
            Assert.AreSame(typeof(FormattedEventLogTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType);
            Assert.AreSame(typeof(FormattedEventLogTraceListener), roSettigs.TraceListeners.Get(name).Type);
            Assert.AreEqual(formatter, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter);
            Assert.AreEqual(log, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).Log);
            Assert.AreEqual(machine, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).MachineName);
            Assert.AreEqual(source, ((FormattedEventLogTraceListenerData)roSettigs.TraceListeners.Get(name)).Source);
        }
開發者ID:HondaBey,項目名稱:EnterpriseLibrary6,代碼行數:32,代碼來源:FormattedEventLogTraceListenerConfigurationFixture.cs

示例6: SetUp

		public void SetUp()
		{
			configurationSource = new DictionaryConfigurationSourceWithHandlersQuery();

			InstrumentationConfigurationSection instrumentationConfig = new InstrumentationConfigurationSection(true, true, true);
			configurationSource.Add(InstrumentationConfigurationSection.SectionName, instrumentationConfig);

			settings = new LoggingSettings();
			configurationSource.Add(LoggingSettings.SectionName, settings);

			settings.SpecialTraceSources.ErrorsTraceSource
				= new TraceSourceData("error", SourceLevels.Off);

			TraceSourceData traceSourceData = new TraceSourceData("blocking", SourceLevels.All);
			traceSourceData.TraceListeners.Add(new TraceListenerReferenceData("listener1"));
			settings.TraceSources.Add(traceSourceData);
			traceSourceData = new TraceSourceData("nonblocking", SourceLevels.All);
			traceSourceData.TraceListeners.Add(new TraceListenerReferenceData("listener2"));
			settings.TraceSources.Add(traceSourceData);

			TraceListenerData traceListenerData = new CustomTraceListenerData("listener1", typeof(MockBlockingCustomTraceListener), "init 1");
			settings.TraceListeners.Add(traceListenerData);
			traceListenerData = new MockTraceListenerData("listener2");
			settings.TraceListeners.Add(traceListenerData);

			reflectionCache = new ConfigurationReflectionCache();

			MockTraceListener.Reset();
			MockBlockingCustomTraceListener.Reset();
		}
開發者ID:ChiangHanLung,項目名稱:PIC_VDS,代碼行數:30,代碼來源:LogWriterSingletonManagementFixture.cs

示例7: CanDeserializeSerializedConfiguration

		public void CanDeserializeSerializedConfiguration()
		{
			string name = "name";
			string filename = "filename";
			string header = "header";
			string footer = "footer";
			string formatter = "formatter";

			TraceListenerData data = new FlatFileTraceListenerData(name, filename, header, footer,
													formatter, TraceOptions.Callstack);

			LoggingSettings settings = new LoggingSettings();
			settings.TraceListeners.Add(data);

			IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
			sections[LoggingSettings.SectionName] = settings;
			IConfigurationSource configurationSource
				= ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

			LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

			Assert.AreEqual(1, roSettigs.TraceListeners.Count);
			Assert.IsNotNull(roSettigs.TraceListeners.Get(name));
			Assert.AreEqual(TraceOptions.Callstack, roSettigs.TraceListeners.Get(name).TraceOutputOptions);
			Assert.AreSame(typeof(FlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).GetType());
			Assert.AreSame(typeof(FlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType);
			Assert.AreSame(typeof(FlatFileTraceListener), roSettigs.TraceListeners.Get(name).Type);
			Assert.AreEqual(filename, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).FileName);
			Assert.AreEqual(footer, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Footer);
			Assert.AreEqual(formatter, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter);
			Assert.AreEqual(header, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Header);
		}
開發者ID:ChiangHanLung,項目名稱:PIC_VDS,代碼行數:32,代碼來源:FormattedFlatFileTraceListenerConfigurationFixture.cs

示例8: CanDeserializeSerializedCollection

		public void CanDeserializeSerializedCollection()
		{
			LoggingSettings rwLoggingSettings = new LoggingSettings();
			rwLoggingSettings.TraceListeners.Add(new FormattedEventLogTraceListenerData("listener1", CommonUtil.EventLogSourceName, "formatter"));
			rwLoggingSettings.TraceListeners.Add(new SystemDiagnosticsTraceListenerData("listener2", typeof(FormattedEventLogTraceListener), CommonUtil.EventLogSourceName));
			rwLoggingSettings.TraceListeners.Add(new SystemDiagnosticsTraceListenerData("listener3", typeof(XmlWriterTraceListener), "foobar.txt"));

			ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
			fileMap.ExeConfigFilename = "test.exe.config";
			System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
			rwConfiguration.Sections.Remove(LoggingSettings.SectionName);
			rwConfiguration.Sections.Add(LoggingSettings.SectionName, rwLoggingSettings);


			File.SetAttributes(fileMap.ExeConfigFilename, FileAttributes.Normal);
			rwConfiguration.Save();

			System.Configuration.Configuration roConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
			LoggingSettings roLoggingSettings = roConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings;

			Assert.AreEqual(3, roLoggingSettings.TraceListeners.Count);

			Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener1"));
			Assert.AreEqual(roLoggingSettings.TraceListeners.Get("listener1").GetType(), typeof(FormattedEventLogTraceListenerData));
			Assert.AreSame(roLoggingSettings.TraceListeners.Get("listener1").Type, typeof(FormattedEventLogTraceListener));

			Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener2"));
			Assert.AreEqual(roLoggingSettings.TraceListeners.Get("listener2").GetType(), typeof(SystemDiagnosticsTraceListenerData));
			Assert.AreSame(roLoggingSettings.TraceListeners.Get("listener2").Type, typeof(FormattedEventLogTraceListener));

			Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener3"));
			Assert.AreEqual(roLoggingSettings.TraceListeners.Get("listener3").GetType(), typeof(SystemDiagnosticsTraceListenerData));
			Assert.AreSame(roLoggingSettings.TraceListeners.Get("listener3").Type, typeof(XmlWriterTraceListener));
		}
開發者ID:ChiangHanLung,項目名稱:PIC_VDS,代碼行數:34,代碼來源:TraceListenerDataCollectionFixture.cs

示例9: CanDeserializeSerializedConfiguration

		public void CanDeserializeSerializedConfiguration()
		{
			LoggingSettings rwLoggingSettings = new LoggingSettings();
			rwLoggingSettings.TraceListeners.Add(
                new EmailTraceListenerData("listener", "[email protected]", "[email protected]", "EntLib-Logging:",
                                                    "has occurred", "smtphost", 25, "formatter"));
            rwLoggingSettings.TraceListeners.Add(
                new EmailTraceListenerData("listener2", "[email protected]", "[email protected]", "EntLib-Logging:",
                                                    "has occurred", "smtphost", 25, "formatter"));

			ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
			fileMap.ExeConfigFilename = "test.exe.config";
			System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
			rwConfiguration.Sections.Remove(LoggingSettings.SectionName);
			rwConfiguration.Sections.Add(LoggingSettings.SectionName, rwLoggingSettings);


			File.SetAttributes(fileMap.ExeConfigFilename, FileAttributes.Normal);				
			rwConfiguration.Save();

			System.Configuration.Configuration roConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
			LoggingSettings roLoggingSettings = roConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings;

			Assert.AreEqual(2, roLoggingSettings.TraceListeners.Count);
			Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener"));
			Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener2"));
		}
開發者ID:ChiangHanLung,項目名稱:PIC_VDS,代碼行數:27,代碼來源:FormatterEmailTraceListenerConfigurationFixture.cs

示例10: SetUp

 public void SetUp()
 {
     loggingSettings = new LoggingSettings();
     connectionStringsSection = new ConnectionStringsSection();
     configurationSource = new DictionaryConfigurationSource();
     configurationSource.Add(LoggingSettings.SectionName, loggingSettings);
     configurationSource.Add("connectionStrings", connectionStringsSection);
 }
開發者ID:jmeckley,項目名稱:Enterprise-Library-5.0,代碼行數:8,代碼來源:FormattedDatabaseTraceListenerPolicyCreatorFixture.cs

示例11: GetLoggingSettings

        ConfigurationSection GetLoggingSettings()
        {
            LoggingSettings loggingConfiguration = null;

            if (!_cache.ContainsKey(LoggingSettingsKey))
            {
                lock (_sync)
                {
                    if (!_cache.ContainsKey(LoggingSettingsKey))
                    {
                        loggingConfiguration = new LoggingSettings();

                        loggingConfiguration.Name = "Logging Application Block";
                        loggingConfiguration.TracingEnabled = true;
                        loggingConfiguration.DefaultCategory = "General";
                        loggingConfiguration.LogWarningWhenNoCategoriesMatch = true;

                        var customTraceListenerData = new CustomTraceListenerData
                                                          {
                                                              ListenerDataType =
                                                                  Type.GetType(
                                                                  "Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"),
                                                              TraceOutputOptions = TraceOptions.None,
                                                              Filter = SourceLevels.All,
                                                              Type =
                                                                  Type.GetType(
                                                                  "NCommons.Logging.EnterpriseLibrary.Specs.TraceListenerSpy, NCommons.Logging.EnterpriseLibrary.Specs"),
                                                              Name = "Custom Trace Listener",
                                                              Formatter = "Text Formatter"
                                                          };

                        loggingConfiguration.TraceListeners.Add(customTraceListenerData);

                        var textFormatterData = new TextFormatterData
                                                    {
                                                        Name = "Text Formatter",
                                                        Type =
                                                            Type.GetType(
                                                            "Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"),
                                                        Template = "{message}"
                                                    };

                        loggingConfiguration.Formatters.Add(textFormatterData);

                        loggingConfiguration.SpecialTraceSources.AllEventsTraceSource.TraceListeners.Add(
                            new TraceListenerReferenceData("Custom Trace Listener"));
                        loggingConfiguration.SpecialTraceSources.AllEventsTraceSource.DefaultLevel =
                            SourceLevels.All;
                        loggingConfiguration.SpecialTraceSources.AllEventsTraceSource.Name = "All Events";

                        _cache[LoggingSettingsKey] = loggingConfiguration;
                    }
                }
            }

            return _cache[LoggingSettingsKey];
        }
開發者ID:bsommardahl,項目名稱:ncommons,代碼行數:57,代碼來源:ConfigurationSourceStub.cs

示例12: SetUp

        public void SetUp()
        {
            instrumentationSettings = new InstrumentationConfigurationSection(true, true);
            loggingSettings = new LoggingSettings();
            configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(LoggingSettings.SectionName, loggingSettings);

            container = new UnityContainer();
        }
開發者ID:jmeckley,項目名稱:Enterprise-Library-5.0,代碼行數:9,代碼來源:LoggingBlockExtensionFixture.cs

示例13: ConfigureLogging

        /// <summary>
        /// Main entry point to configuration a <see cref="LoggingSettings"/> section.
        /// </summary>
        /// <param name="configurationSourceBuilder">The builder interface to extend.</param>
        /// <returns></returns>
        public static ILoggingConfigurationStart ConfigureLogging(this IConfigurationSourceBuilder configurationSourceBuilder)
        {
            if(configurationSourceBuilder == null) throw new ArgumentNullException("configurationSourceBuilder");

            LoggingSettings loggingSettings = new LoggingSettings();
            configurationSourceBuilder.AddSection(LoggingSettings.SectionName, loggingSettings);

            return new LoggingConfigurationBuilder(loggingSettings);
        }
開發者ID:jmeckley,項目名稱:Enterprise-Library-5.0,代碼行數:14,代碼來源:LoggingConfigurationSourceBuilderExtensions.cs

示例14: LogImplementation

 public LogImplementation(SourceLevels level)
 {
     var factory = new LoggingConfigurationSourceFactory();
     var configurationSource = factory.Create(level);
     this.entLibSettings =
         configurationSource.GetSection(EntLib.LoggingSettings.SectionName)
         as EntLib.LoggingSettings;
     this.logWriter = new LogWriterFactory(configurationSource).Create();
     this.loggingEnabled = true;
 }
開發者ID:paulkearney,項目名稱:brnkly,代碼行數:10,代碼來源:LogImplementation.cs

示例15: CanCreateInstanceFromConfigurationFile

        public void CanCreateInstanceFromConfigurationFile()
        {
            LoggingSettings loggingSettings = new LoggingSettings();
            loggingSettings.TraceListeners.Add(
                    new WmiTraceListenerData("listener"));

            TraceListener listener = TraceListenerCustomFactory.Instance.Create(context, "listener", CommonUtil.SaveSectionsAndGetConfigurationSource(loggingSettings), reflectionCache);

            Assert.IsNotNull(listener);
            Assert.AreEqual(listener.GetType(), typeof(WmiTraceListener));
        }
開發者ID:bnantz,項目名稱:NCS-V2-0,代碼行數:11,代碼來源:WmiTraceListenerConfigurationFixture.cs


注:本文中的Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。