本文整理汇总了C#中LogWriter.GetMatchingTraceSources方法的典型用法代码示例。如果您正苦于以下问题:C# LogWriter.GetMatchingTraceSources方法的具体用法?C# LogWriter.GetMatchingTraceSources怎么用?C# LogWriter.GetMatchingTraceSources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogWriter
的用法示例。
在下文中一共展示了LogWriter.GetMatchingTraceSources方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
示例3: 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);
}
示例4: 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);
}