问题:
如何将ILogger声明为类变量并将其用于日志记录?
-
我需要开发以tracewriter为默认值的Azure函数应用程序。
编写UnitTest时,tracewriter很困难。取而代之的是我使用了ILogger。
-
在函数应用程序中,iam将日志变量从初始运行方法传递给所有方法。(这不是正确的方法。)
-
我需要将ILogger声明为一个类变量,并在所有地方使用它们。
所以,怎么做。
示例代码
public class addClass
{
// private static ILogger LOGGER = ---???----- // I need to declare here.
private void add(ILogger log) // Iam using like this. This is not rite way of programming to pass to all methods.
{
int a = 10;
int b=4;
log.LogInformation((a+b));
}
private void addM() // Using the class variable.
{
int a = 10;
int b = 4;
log.LogInformation((a+b));
}
}