简体   繁体   English

基本NLog文件目标在IIS 8和Windows Server 2012下不起作用

[英]Basic NLog file target not working under IIS 8 and Windows Server 2012

I just can't make NLog to work reliably under Windows Server 2012/IIS 8. This is an Azure Virtual Machine (not a webrole) so things should have been pretty simple. 我只是不能使NLog在Windows Server 2012 / IIS 8下可靠地工作。这是一个Azure虚拟机(不是webrole),因此事情应该非常简单。 Originally I had acync wrappers, database-based targets, etc. But I've stripped everything down to the bare mininum and can't seem to make it work! 最初,我有acync包装器,基于数据库的目标等。但是我已经将所有内容都剥离到了最低限度,似乎无法使其正常运行!

This is my NLog.config file: 这是我的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="nsec"
             fileName="${basedir}app_data/logs/nsec_${shortdate}.log"
             createDirs="true"
             layout="${longdate}|${level:uppercase=true}|${logger}|${aspnet-user-identity}|${message}"
             />
    </targets>

  <rules>
    <logger name="NSec" minlevel="Trace" writeTo="nsec"/> 
  </rules>
</nlog>

As you can see, there's nothing fancy here. 如您所见,这里没有任何幻想。 The file target should have written to the ./App_Data/Logs directory, but most of the time nothing got written there. 目标文件应该已经写入./App_Data/Logs目录,但是大多数时候没有写入任何内容。 Sometimes something gets written to the file... And that's the most infuriating part of it all! 有时某些内容会写入文件中……这是所有内容中最令人毛骨悚然的部分!

Locally under both Cassini and IIS Express the logs work perfectly. 在Cassini和IIS Express本地都可以正常运行日志。

Is there anything I need to add to my web.config for NLog to work? 为了使NLog正常工作,我需要添加任何内容到我的web.config中吗? I'm not even using the ASP.NET wrapper! 我什至没有使用ASP.NET包装器!

Does anyone know of any incompatibility between NLog and IIS8? 有人知道NLog和IIS8之间有任何不兼容吗?

UPDATE UPDATE

I've run Process Monitor on the server and realized not even a single attempt is made to write, read, or query the log file. 我已经在服务器上运行Process Monitor,并且意识到什至没有尝试写入,读取或查询日志文件。 It looks as if NLog was being completely and utterly ignored. 似乎完全完全忽略了NLog。 I know the NLog.config file is being read at startup because if I put an invalid configuration I get an error when accessing my application, so NLog is parsing the file. 我知道启动时会读取NLog.config文件,因为如果我输入了无效的配置,则在访问应用程序时会收到错误消息,因此NLog会解析该文件。 The problem is that even though it is being parsed, and sometimes something gets logged, most of the time NOTHING happens, and, as confirmed by using Process Monitor, not a single attempt is being made to access/create/write the log file. 问题在于,即使正在解析它,有时记录了某些内容,大多数情况下都不会发生,并且,通过使用Process Monitor的确认,并没有尝试访问/创建/写入日志文件。

The irony is that on Process Monitor I could see the other IIS Applications writing to their own NLog files without issues. 具有讽刺意味的是,在Process Monitor上,我可以看到其他IIS应用程序写入其自己的NLog文件而没有问题。 It's only this specific application that is failing to log, but only in the production machine! 只是该特定应用程序无法记录日志,而仅在生产机器中!

I've just discovered, with the help of Uwe Kein, who suggested me to use Process Monitor to see if there was any problems with permissions that, in fact, the log file was NEVER even accessed. 我刚刚在Uwe Kein的帮助下发现了他,他建议我使用Process Monitor来查看权限是否存在任何问题,实际上,甚至从未访问过日志文件。 This started me wondering why... And I just realized that the HttpModule which was the source of the NSec logger was not running at all, so, in fact, no log was actually ever being made. 这让我想知道为什么...而且我刚刚意识到作为NSec记录器来源的HttpModule根本没有运行,因此,实际上实际上没有记录过日志。

This problem occurred because the web.config on the destination machine wasn't successfully updated in previous deployments, so the HttpModule was configured the IIS6 way... I had to add it to the modules section as shown in: https://stackoverflow.com/a/2935410/285678 发生此问题的原因是,在先前的部署中未成功更新目标计算机上的web.config,因此以IIS6方式配置了HttpModule ...我必须将其添加到模块部分,如下所示: https:// stackoverflow的.com /一个/285678分之2935410

What is great about it was that I've just added this log to try to find the reason why this HttpModule was not behaving as expected, so finding out why NLog was "not working" resolved this issue (which was a very serious issue, as the HttpModule pertained to the security system of the application!) 这样做的好处是,我刚刚添加了此日志以尝试查找此HttpModule的行为不符合预期的原因,因此找出NLog为何“不起作用”的原因解决了该问题(这是一个非常严重的问题,因为HttpModule属于应用程序的安全系统!)

I've tried to close the question since it is misleading, as it is not an NLog error at all, but it needs 50 votes to be closed! 我试图结束这个问题,因为它具有误导性,因为它根本不是NLog错误,但需要50票才能解决! So I'll left it as a warning to people like me who, in desperation, ask "not very wise" questions in StackOverflow :-( 因此,我将其警告给像我这样的人,他们在绝望中在StackOverflow中问“不是很明智”的问题:-(

I had put a blank Nlog config section in the web.config file, and that made it not look for the nlog.config file. 我在web.config文件中放置了一个空白的Nlog config部分,这使得它不寻找nlog.config文件。 Once I deleted that, my logging started working. 删除后,我的日志记录开始工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM