本文整理汇总了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);
}
示例2: ValidateLoggingSettings
private void ValidateLoggingSettings(LoggingSettings loggingSettings)
{
if (loggingSettings == null)
{
throw new System.Configuration.ConfigurationErrorsException(Resources.ExceptionLoggingSectionNotFound);
}
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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));
}
示例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"));
}
示例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];
}
示例12: SetUp
public void SetUp()
{
instrumentationSettings = new InstrumentationConfigurationSection(true, true);
loggingSettings = new LoggingSettings();
configurationSource = new DictionaryConfigurationSource();
configurationSource.Add(LoggingSettings.SectionName, loggingSettings);
container = new UnityContainer();
}
示例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;
}
示例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));
}