【发布时间】:2018-12-15 16:10:25
【问题描述】:
我有下面的代码来创建一个日志文件。
public class LoggingService
{
private readonly IHostingEnvironment env;
public LoggingService(IHostingEnvironment env)
{
this.env = env;
}
public void WriteLog(string strLog)
{
//Some code is Here
}
}
在控制器函数中访问类
LoggingService log = new LoggingService();
log.WriteLog("Inside GetUserbyCredential function");
当我尝试从控制器类创建实例以将某些值传递给函数时。当时我收到以下错误
没有给出与“LoggingService.LoggingService(IHostingEnvironment)”的所需形式参数“env”相对应的参数
如何为此创建实例。
【问题讨论】:
-
您如何使用
LoggingService类?您能否添加使用 LoggingService 的代码,即创建/注入到控制器中,以及您的startup.cs(尤其是在您注册LoggingService类的地方)。 -
我没有在 startup.cs 中做任何事情
标签: c# asp.net-core .net-core asp.net-core-mvc