NLog is not logging

吃可爱长大的小学妹 提交于 2019-12-10 21:45:49

问题


I am using the new NLog 2.0. I have set it up both manually and with the aid of NuGet on 2 different platforms:

1) on a Visual Web Developer express 2010 back at home.

2) On a Visual Studio 2010 in office.

In both cases I just cant get it to log.

I have read all of the options suggested here with no luck.

I am using the very basic configuration from the first tutorial.

<?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"
  throwExceptions="true">

<targets>
 <target name="logfile" xsi:type="File" fileName="${basedir}/file.txt" />
</targets>

 <rules>
  <logger name="*" minlevel="Info" writeTo="logfile"/>
 </rules>
</nlog>

And here is how I am calling the logger:

public partial class _Default : System.Web.UI.Page
{
    Logger logger = LogManager.GetCurrentClassLogger();

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        logger.Fatal("Hello Log!");
    }
}

I get no exceptions!

Am I doing anything wrong here?? What am I missing.

PS

I have set the NLog.config to "Copy always" so that's not the case either.


回答1:


I had to restart Visual Studio and it suddenly start working.

It didn't occur to me that this is needed!

Any way sorry for that...



来源:https://stackoverflow.com/questions/8118695/nlog-is-not-logging

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!