为什么不工作的$ {} BASEDIR配置NLOG? [英] Why is the ${basedir} NLog configuration not working?

查看:939
本文介绍了为什么不工作的$ {} BASEDIR配置NLOG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我不能在我的生产服务器上使用$ {} BASEDIR nlog.config?如果我使用文件名=$ {BASEDIR} /日志/ $ {} shortdate .LOG,n日志不记录消息的信息,但如果我更改为类似文件名=C:/日志/ $ {} shortdate .LOG将记录消息信息

我nlog.config:

<?XML版本=1.0编码=UTF-8&GT?;
< n日志的xmlns =htt​​p://www.nlog-project.org/schemas/NLog.xsd
      XMLNS:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance>  <靶标GT;
    <目标的xsi:type =文件NAME =F文件名=$ {BASEDIR} /日志/ $ {} shortdate .LOG
            布局=$ {的longdate} $ {大写:$ {}级} $ {}消息/>
  < /目标>  <规则与GT;
    <记录器名称=*定义的MinLevel =跟踪中的writeTo =F/>
  < /规则>
< / n日志>

控制器:

公共类HomeController的:控制器
{
    私有静态记录器记录= LogManager.GetCurrentClassLogger();    公众的ActionResult指数()
    {
        logger.Debug(测试NLOG);
        返回查看();
    }
}


解决方案

此问题是文件权限有关。简短的故事:在Web应用程序正在运行的不具有权限写入日志文件中的用户

根据.NET的版本和IIS的版本,也有不同的用户,这可能是的。

有关IIS 6,我要说的是,Web应用程序正在运行的 NETWORK SERVICE 帐户。

因此​​,你需要将授予该用户权限为写/修改日志文件夹(我presume是一个子Web根目录的-folder)。如果你想在日志文件夹被NLOG自动创建的,你需要这些权限授予网站根目录来代替。

Why I cannot use ${basedir} nlog.config in my production server? If I use fileName="${basedir}/logs/${shortdate}.log", nlog does not log the message info, but if I change to something like fileName="C:/logs/${shortdate}.log" it will log the message info

my 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>

Controller:

public class HomeController : Controller
{
    private static Logger logger = LogManager.GetCurrentClassLogger();

    public ActionResult Index()
    {
        logger.Debug("Test NLog");
        return View();
    }
}

解决方案

This issue is related to file permission. Short story: the user that the web application is running as does not have permission to write the log files.

Depending on the version of .NET and the version of IIS, there are a variety of users that it could be.

For IIS 6, I would say that the web application is running as the NETWORK SERVICE account.

Therefore, you will need to grant this user permission to write/modify the logs folder (which I presume is a sub-folder of the web root). If you want the logs folder to be created automatically by NLog, you'll need to grant these permissions to the web root instead.

这篇关于为什么不工作的$ {} BASEDIR配置NLOG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆