控制台输出日志。
安装Microsoft.Extensions.Logging
和Microsoft.Extensions.Logging.Console
简单使用
static void Main(string[] args)
{
ServiceCollection sc=new ServiceCollection();
sc.AddLogging(logBuilder=>logBuilder.AddConsole());
sc.AddScoped<Test>();
var sp = sc.BuildServiceProvider();
Test test = sp.GetRequiredService<Test>();
test.logTest();
}
public class Test
{
private ILogger<Test> log;
public Test(ILogger<Test> log)
{
this.log = log;
}
public void logTest()
{
log.LogDebug("Debug:开始调试");
log.LogInformation("info:默认日志");
log.LogWarning("warn:警告日志");
log.LogError("Error:错误日志");
}
}