我在我的MVC項目中使用Nlog如何在MVC中使用Nlog將消息記錄到txt文件?
我想實現的是在控制器中執行操作方法時記錄消息。並且日誌消息應該出現在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>
,然後在我的控制我的POST操作方法裏面我有以下代碼:
[HttpPost]
public ActionResult Edit(int id, CreateNKIphase1ViewModel model)
{
Logger logger = LogManager.GetCurrentClassLogger();
logger.Info("Test message");
//code....
}
我在哪裏可以找到TXT文件?
這是爲什麼不工作:S