本文整理汇总了C#中LogSource.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# LogSource.Dispose方法的具体用法?C# LogSource.Dispose怎么用?C# LogSource.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LogSource
的用法示例。
在下文中一共展示了LogSource.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FlatFileListenerWillFallbackIfNotPriviledgesToWrite
public void FlatFileListenerWillFallbackIfNotPriviledgesToWrite()
{
string fileName = @"trace.log";
string fullPath = String.Format(@"{0}\{1}", Directory.GetCurrentDirectory(), fileName);
File.Delete(fileName);
FileIOPermission fileIOPerm1 = new FileIOPermission(PermissionState.None);
fileIOPerm1.SetPathList(FileIOPermissionAccess.Read, fullPath);
fileIOPerm1.PermitOnly();
try
{
FlatFileTraceListener listener = new FlatFileTraceListener(fileName,"---header---","***footer***",new TextFormatter("DUMMY{newline}DUMMY"));
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null));
source.Dispose();
}
catch (SecurityException)
{
FileIOPermission.RevertAll();
throw;
}
}
示例2: ListenerWithHeaderAndFooterWillUseFormatterIfExists
public void ListenerWithHeaderAndFooterWillUseFormatterIfExists()
{
File.Delete("tracewithheaderandfooter.log");
FlatFileTraceListener listener = new FlatFileTraceListener("tracewithheaderandfooter.log", "--------header------", "=======footer===========", new TextFormatter("DUMMY{newline}DUMMY"));
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null));
source.Dispose();
string strFileContents = GetFileContents("tracewithheaderandfooter.log");
Assert.AreEqual("--------header------" + Environment.NewLine + "DUMMY" + Environment.NewLine + "DUMMY" + Environment.NewLine + "=======footer===========" + Environment.NewLine, strFileContents);
}
示例3: ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists
public void ListenerWillFallbackToTraceEntryToStringIfFormatterDoesNotExists()
{
LogEntry testLogEntry = new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null);
StreamWriter writer = new StreamWriter("trace.log");
FlatFileTraceListener listener = new FlatFileTraceListener(writer);
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
source.TraceData(TraceEventType.Error, 0, testLogEntry);
source.Dispose();
string strFileContents = GetFileContents("trace.log");
string testLogEntryAsString = testLogEntry.ToString();
Assert.IsTrue(-1 != strFileContents.IndexOf(testLogEntryAsString));
}
示例4: FlatFileTraceListenerMultipleWrites
public void FlatFileTraceListenerMultipleWrites()
{
File.Delete("tracewithheaderandfooter.log");
string header = "--------header------";
int numberOfWrites = 4;
FlatFileTraceListener listener = new FlatFileTraceListener("tracewithheaderandfooter.log", header, "=======footer===========", new TextFormatter("DUMMY{newline}DUMMY"));
// need to go through the source to get a TraceEventCache
LogSource source = new LogSource("notfromconfig", SourceLevels.All);
source.Listeners.Add(listener);
for (int writeLoop = 0; writeLoop < numberOfWrites; writeLoop++)
source.TraceData(TraceEventType.Error, 0, new LogEntry("message", "cat1", 0, 0, TraceEventType.Error, "title", null));
source.Dispose();
StreamReader reader = new StreamReader("tracewithheaderandfooter.log");
int headersFound = NumberOfItems("tracewithheaderandfooter.log", header);
Assert.AreEqual(numberOfWrites,headersFound);
}