本文整理匯總了C#中System.Logger.SetWriter方法的典型用法代碼示例。如果您正苦於以下問題:C# Logger.SetWriter方法的具體用法?C# Logger.SetWriter怎麽用?C# Logger.SetWriter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Logger
的用法示例。
在下文中一共展示了Logger.SetWriter方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Debug_WithoutCategoryAdded
public void Debug_WithoutCategoryAdded()
{
// arrange
var logger = new Logger();
var logs = new StringBuilder();
logger.SetWriter(new StringWriter(logs));
// act
logger.Debug("debug message");
// assert
Assert.Equal(string.Empty, logs.ToString());
}
示例2: Error
public void Error()
{
// arrange
var logger = new Logger();
var logs = new StringBuilder();
logger.SetWriter(new StringWriter(logs));
logger.AddCategory("error");
// act
logger.Debug("debug message");
logger.Info("info message");
logger.Error("error message");
// assert
Assert.Equal("error message", logs.ToString().Trim());
}
示例3: GetLogger
private Logger GetLogger()
{
_loggerOutput = new StringBuilder();
var writer = new StringWriter(_loggerOutput);
var logger = new Logger();
logger.SetWriter(writer);
logger.AddCategory("info");
logger.AddCategory("error");
return logger;
}