Obs*_*vus 4 c# asp.net-mvc logging nlog asp.net-mvc-3
我在我的MVC项目中使用Nlog
我想要实现的是在我的控制器中执行操作方法时记录消息.并且日志消息应出现在txt文件中.但我似乎无法让它发挥作用
我已将Nlog安装到我的参考资料中.
我有Nlog.Config,配置如下:
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file"
xsi:type="File"
layout="${longdate} ${logger} ${message}"
fileName="${basedir}/logs/logfile.txt"
keepFileOpen="false"
encoding="iso-8859-2" />
</targets>
<rules>
<logger name="*"
minlevel="Debug"
writeTo="file" />
</rules>
</nlog>
Run Code Online (Sandbox Code Playgroud)
然后在我的控制器中的POST动作方法中,我有以下代码:
[HttpPost]
public ActionResult Edit(int id, CreateNKIphase1ViewModel model)
{
Logger logger = LogManager.GetCurrentClassLogger();
logger.Info("Test message");
//code....
}
Run Code Online (Sandbox Code Playgroud)
我在哪里可以找到txt文件?
为什么这不起作用:S
如果您的应用程序使用应用程序池标识在IIS中运行,则需要为该标识授予文件夹权限.
输入应用程序池标识的名称时,您需要包括IIS APPPOOL.例如,如果是应用程序池标识ASP.NET v4.0,请输入名称IIS APPPOOL\ASP.NET v4.0.此外,请确保该位置是本地计算机,而不是网络域.