本文整理匯總了C#中System.Log.WriteLine方法的典型用法代碼示例。如果您正苦於以下問題:C# Log.WriteLine方法的具體用法?C# Log.WriteLine怎麽用?C# Log.WriteLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Log
的用法示例。
在下文中一共展示了Log.WriteLine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteLineTest
public void WriteLineTest()
{
var logFilename = Path.Combine(_logFileDirectory, "logtest.txt");
using (var sw = new StreamWriter(logFilename))
{
var log = new Log(sw);
log.WriteLine(LogEntryType.Info, "info log entry");
log.WriteLine(LogEntryType.Warning, "warning log entry");
log.WriteLine(LogEntryType.Error, "error log entry");
}
var logFileContents = File.ReadAllLines(logFilename);
/*
Log entries look like this:
2013-01-26T02:00:26.3637578Z - INF - Hello, world!
2013-01-26T02:00:26.3793828Z - WRN - Hello, world!
2013-01-26T02:00:26.3793828Z - ERR - Hello, world!
*/
Assert.IsTrue(this.DoesMatchLogEntryFormat(logFileContents[0], "INF", "info log entry"), logFileContents[0]);
Assert.IsTrue(this.DoesMatchLogEntryFormat(logFileContents[1], "WRN", "warning log entry"), logFileContents[1]);
Assert.IsTrue(this.DoesMatchLogEntryFormat(logFileContents[2], "ERR", "error log entry"), logFileContents[2]);
}