本文整理汇总了C#中LogWriter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# LogWriter.Dispose方法的具体用法?C# LogWriter.Dispose怎么用?C# LogWriter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogWriter
的用法示例。
在下文中一共展示了LogWriter.Dispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanFindMatchingCategories
public void CanFindMatchingCategories()
{
Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
traceSources.Add("newcat1", new LogSource("newcat1"));
traceSources.Add("newcat2", new LogSource("newcat2"));
traceSources.Add("newcat3", new LogSource("newcat3"));
traceSources.Add("newcat4", new LogSource("newcat4"));
LogWriter logWriter = new LogWriter(emptyFilters, traceSources, new LogSource("errors"), "default");
string[] categories = new string[] { "newcat1", "newcat2", "newcat5", "newcat6" };
LogEntry logEntry = new LogEntry();
logEntry.Categories = categories;
IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);
logWriter.Dispose();
Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
foreach (LogSource traceSource in matchingTraceSources)
{
matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
}
Assert.AreEqual(2, matchingTraceSourcesDictionary.Count);
Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[0]));
Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[1]));
Assert.IsFalse(matchingTraceSourcesDictionary.ContainsKey(categories[2]));
}
示例2: MissingCategoriesWarningIsLoggedIfLogWarningFlagIsTrue
public void MissingCategoriesWarningIsLoggedIfLogWarningFlagIsTrue()
{
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogSource failingTraceSource = new LogSource("logging", SourceLevels.All);
failingTraceSource.Listeners.Add(new MockTraceListener());
LogSource loggingTraceSource = new LogSource("logging2", SourceLevels.All);
loggingTraceSource.Listeners.Add(new MockTraceListener());
LogWriter writer =
new LogWriter(new ILogFilter[0],
new LogSource[] { failingTraceSource, loggingTraceSource },
emptyTraceSource,
emptyTraceSource,
errorsTraceSource,
"default",
false,
true);
LogEntry logEntry = new LogEntry();
logEntry.Message = originalMessage;
logEntry.Severity = TraceEventType.Critical;
logEntry.Categories = new string[] { "logging", "logging2", "logging3" };
writer.Write(logEntry);
writer.Dispose();
Assert.AreEqual(1, ErrorsMockTraceListener.Entries.Count);
Assert.AreEqual(TraceEventType.Error, ErrorsMockTraceListener.LastEntry.Severity);
Assert.IsTrue(MatchTemplate(ErrorsMockTraceListener.LastEntry.Message, Resources.MissingCategories));
Assert.AreEqual(2, MockTraceListener.Entries.Count);
Assert.AreSame(logEntry, MockTraceListener.LastEntry);
}
示例3: NoErrorsWhileSendingToTraceSourceOnlyLogsOriginalMessageToCategoryTraceSources
public void NoErrorsWhileSendingToTraceSourceOnlyLogsOriginalMessageToCategoryTraceSources()
{
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogSource failingTraceSource = new LogSource("logging", SourceLevels.All);
failingTraceSource.Listeners.Add(new MockTraceListener());
LogSource loggingTraceSource = new LogSource("logging2", SourceLevels.All);
loggingTraceSource.Listeners.Add(new MockTraceListener());
LogWriter writer =
new LogWriter(new ILogFilter[0],
new LogSource[] { failingTraceSource, loggingTraceSource },
errorsTraceSource,
"default");
LogEntry logEntry = new LogEntry();
logEntry.Message = originalMessage;
logEntry.Severity = TraceEventType.Critical;
logEntry.Categories = new string[] { "logging", "logging2" };
writer.Write(logEntry);
writer.Dispose();
Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
Assert.AreEqual(2, MockTraceListener.Entries.Count);
Assert.AreSame(logEntry, MockTraceListener.LastEntry);
}
示例4: ErrorWhileSendingToTraceSourceLogsWarningAndLogsOriginalMessageToNonFailingTraceSources
public void ErrorWhileSendingToTraceSourceLogsWarningAndLogsOriginalMessageToNonFailingTraceSources()
{
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogSource failingTraceSource = new LogSource("failing", SourceLevels.All);
failingTraceSource.Listeners.Add(new ExceptionThrowingMockTraceListener());
LogSource loggingTraceSource = new LogSource("logging", SourceLevels.All);
loggingTraceSource.Listeners.Add(new MockTraceListener());
LogWriter writer =
new LogWriter(new ILogFilter[0],
new LogSource[] { failingTraceSource, loggingTraceSource },
errorsTraceSource,
"default");
LogEntry logEntry = new LogEntry();
logEntry.Message = originalMessage;
logEntry.Severity = TraceEventType.Critical;
logEntry.Categories = new string[] { "failing", "logging" };
writer.Write(logEntry);
writer.Dispose();
Assert.AreEqual(1, ErrorsMockTraceListener.Entries.Count);
Assert.AreEqual(TraceEventType.Error, ErrorsMockTraceListener.LastEntry.Severity);
Assert.IsTrue(MatchTemplate(ErrorsMockTraceListener.LastEntry.Message, Resources.TraceSourceFailed));
Assert.AreEqual(1, MockTraceListener.Entries.Count);
Assert.AreSame(logEntry, MockTraceListener.LastEntry);
}
示例5: UsesDefaultTraceSourceIfThereAreMissingCategoriesAndDefaultIsConfiguredAndMandatoryIsNotConfigured
public void UsesDefaultTraceSourceIfThereAreMissingCategoriesAndDefaultIsConfiguredAndMandatoryIsNotConfigured()
{
Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
traceSources.Add("newcat1", new LogSource("newcat1"));
traceSources.Add("newcat2", new LogSource("newcat2"));
traceSources.Add("newcat3", new LogSource("newcat3"));
traceSources.Add("newcat4", new LogSource("newcat4"));
LogSource mandatoryTraceSource = null;
LogSource defaultTraceSource = new LogSource("default");
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogWriter logWriter =
new LogWriter(emptyFilters, traceSources, mandatoryTraceSource, defaultTraceSource, errorsTraceSource, "default", false, false);
string[] categories = new string[] { "newcat1", "newcat2", "newcat5", "newcat6" };
LogEntry logEntry = new LogEntry();
logEntry.Categories = categories;
IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);
logWriter.Dispose();
Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
foreach (LogSource traceSource in matchingTraceSources)
{
matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
}
Assert.AreEqual(3, matchingTraceSourcesDictionary.Count);
Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[0]));
Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[1]));
Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(defaultTraceSource.Name));
Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
}
示例6: DoesNotReportMissingCategoriesWhenThereAreNotMissingCategoriesAndDefaultIsNotConfigured
public void DoesNotReportMissingCategoriesWhenThereAreNotMissingCategoriesAndDefaultIsNotConfigured()
{
Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
traceSources.Add("newcat1", new LogSource("newcat1"));
traceSources.Add("newcat2", new LogSource("newcat2"));
traceSources.Add("newcat3", new LogSource("newcat3"));
traceSources.Add("newcat4", new LogSource("newcat4"));
LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
LogWriter logWriter = new LogWriter(emptyFilters, traceSources, emptyTraceSource, emptyTraceSource, errorsTraceSource, "default", false, false);
string[] categories = new string[] { "newcat1", "newcat2" };
LogEntry logEntry = new LogEntry();
logEntry.Categories = categories;
IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);
logWriter.Dispose();
Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
foreach (LogSource traceSource in matchingTraceSources)
{
matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
}
Assert.AreEqual(2, matchingTraceSourcesDictionary.Count);
Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
}
示例7: DisposingWriterThrowsObjectDisposedExceptionWhenUsed
public void DisposingWriterThrowsObjectDisposedExceptionWhenUsed()
{
var writer = new LogWriter(new LoggingConfiguration());
writer.Dispose();
AssertEx.Throws<ObjectDisposedException>(() => writer.Write("Should throw."));
}
示例8: DisposingWriterDisposesAllTraceListenersOnce
public void DisposingWriterDisposesAllTraceListenersOnce()
{
var traceListener = new MockDisposableTraceListener();
var config = new LoggingConfiguration();
config.AddLogSource("cat1", traceListener);
config.AddLogSource("cat2", traceListener);
config.SpecialSources.AllEvents.Listeners.Add(traceListener);
var logWriter = new LogWriter(config);
logWriter.Dispose();
Assert.AreEqual(1, traceListener.DisposedCalls);
}
示例9: UsedMandatoryTraceSourceIfAllCategoriesAreMissing
public void UsedMandatoryTraceSourceIfAllCategoriesAreMissing()
{
Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
traceSources.Add("newcat1", new LogSource("newcat1"));
traceSources.Add("newcat2", new LogSource("newcat2"));
traceSources.Add("newcat3", new LogSource("newcat3"));
traceSources.Add("newcat4", new LogSource("newcat4"));
LogSource mandatoryTraceSource = new LogSource("mandatory");
LogSource errorsTraceSource = new LogSource("errors", new[] { new ErrorsMockTraceListener() }, SourceLevels.All);
LogWriter logWriter = new LogWriter(emptyFilters, traceSources, mandatoryTraceSource, emptyTraceSource, errorsTraceSource, "default", false, false);
string[] categories = new string[] { "newcat5", "newcat6" };
LogEntry logEntry = new LogEntry();
logEntry.Categories = categories;
IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);
logWriter.Dispose();
Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
foreach (LogSource traceSource in matchingTraceSources)
{
matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
}
Assert.AreEqual(1, matchingTraceSourcesDictionary.Count);
Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(mandatoryTraceSource.Name));
Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
}