[英]Why is the ${basedir} NLog configuration not working?
為什么我不能在生產服務器中使用$ {basedir} nlog.config? 如果我使用fileName="${basedir}/logs/${shortdate}.log"
,則nlog不會記錄消息信息,但如果我更改為fileName="C:/logs/${shortdate}.log"
它會記錄消息信息
我的nlog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="f" />
</rules>
</nlog>
控制器:
public class HomeController : Controller
{
private static Logger logger = LogManager.GetCurrentClassLogger();
public ActionResult Index()
{
logger.Debug("Test NLog");
return View();
}
}
此問題與文件權限有關。 簡短的說明:運行Web應用程序的用戶沒有寫日志文件的權限。
根據.NET的版本和IIS的版本,可能有多種用戶。
對於IIS 6,我會說Web應用程序作為NETWORK SERVICE
帳戶運行。
因此,您需要授予此用戶寫入/修改 logs
文件夾的權限(我假設它是Web根目錄的子文件夾)。 如果您希望NLog自動創建logs
文件夾,則需要將這些權限授予Web根目錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.