【发布时间】:2019-05-31 14:08:59
【问题描述】:
是否可以在我的 ASP.NET Core Web 应用程序使用该库的类库中使用 Microsoft.Extensions.Logging 就像在控制器中使用日志记录(放入构造函数和框架使用 DI 处理它)?以及如何实例化类和使用方法?
public class MyMathCalculator
{
private readonly ILogger<MyMathCalculator> logger;
public MyMathCalculator(ILogger<MyMathCalculator> logger)
{
this.logger = logger;
}
public int Fact(int n)
{
//logger.LogInformation($"Fact({n}) called.");
if (n == 0)
{
return 1;
}
return Fact(n - 1) * n;
}
}
【问题讨论】:
-
当然,为什么不呢?
-
是的,你可以,你试过什么?
-
@rekiem87 更新问题,我的问题是如何实例化类。
标签: c# asp.net-core logging .net-core