Nlog Logger.Info 不起作用

发布于 2024-12-14 09:50:16 字数 1982 浏览 4 评论 0原文

我有一个通过 jquery 使用的 Web 服务...现在的问题是我想从 nlog 中进行一些调试,以便我可以看到流程实际上是如何进行的..我认为 nlog 的调试选项... 这是我的配置和代码

<targets>
<target name="file" xsi:type="File"
    layout="${longdate} ${logger} ${message}"
    fileName="${basedir}/Logs/${shortdate}.log" />
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="file"  />
<logger name="*" minlevel="Error" writeTo="file" />
<logger name="*" minlevel="Fatal" writeTo="file" />
<logger name="*" minlevel="Info" writeTo="file" />
</rules>

,我给出的用于获取调试信息的记录器类是

[ScriptService]
public class Service : System.Web.Services.WebService
{
    Logger logger = LogManager.GetCurrentClassLogger();
    [WebMethod]
    public String GetAgentDetails(String AgentId)
    {
        logger.Info("This is webservice");
        String result = string.Empty;
        try
        {
            using (ISession session = NhibernateHelper.Opensession())
            {
                logger.Info("Enters Session");
                 var agent = GetAgent(); // Gets the agent object
                 result = JsonConvert.SerializeObject(agent);
                 logger.Info(result);
                 return result;
            }
        }
        catch (InvalidOperationException ioe)
        {
            logger.Error(ioe.Message);
            logger.Fatal(ioe.Message);
            logger.Error(ioe.InnerException);
            logger.Fatal(ioe.InnerException);
            return null;
        }
        catch (Exception ex)
        {
            logger.Error(ex.Message);
            logger.Fatal(ex.Message);
            logger.Error(ex.InnerException);
            logger.Fatal(ex.InnerException);
        }
        return result;
    }
}

通过 jquery 脚本访问时,它应该在我编写的 logger.info(result) 位置写入日志信息,但似乎没有创建日志文件.有人可以解释一下问题是什么吗?然而,相同的日志文件适用于所有其他类。没有问题。如果抛出异常,则会创建日志文件并写入日志。但在这种情况下,对于 logger.info 来说,它没有发生。我正在使用 Nlog 2.0 和 Asp.net 3.5 SP1 。

i have a webservice which is consumed via jquery ... now the problem is i want to put some debug into from nlog so that i can see how the flow is actually going .. i thought nlog's option for debuging ....
here is my config and code

<targets>
<target name="file" xsi:type="File"
    layout="${longdate} ${logger} ${message}"
    fileName="${basedir}/Logs/${shortdate}.log" />
</targets>

<rules>
<logger name="*" minlevel="Debug" writeTo="file"  />
<logger name="*" minlevel="Error" writeTo="file" />
<logger name="*" minlevel="Fatal" writeTo="file" />
<logger name="*" minlevel="Info" writeTo="file" />
</rules>

and the logger class where i have given for getting debug information is

[ScriptService]
public class Service : System.Web.Services.WebService
{
    Logger logger = LogManager.GetCurrentClassLogger();
    [WebMethod]
    public String GetAgentDetails(String AgentId)
    {
        logger.Info("This is webservice");
        String result = string.Empty;
        try
        {
            using (ISession session = NhibernateHelper.Opensession())
            {
                logger.Info("Enters Session");
                 var agent = GetAgent(); // Gets the agent object
                 result = JsonConvert.SerializeObject(agent);
                 logger.Info(result);
                 return result;
            }
        }
        catch (InvalidOperationException ioe)
        {
            logger.Error(ioe.Message);
            logger.Fatal(ioe.Message);
            logger.Error(ioe.InnerException);
            logger.Fatal(ioe.InnerException);
            return null;
        }
        catch (Exception ex)
        {
            logger.Error(ex.Message);
            logger.Fatal(ex.Message);
            logger.Error(ex.InnerException);
            logger.Fatal(ex.InnerException);
        }
        return result;
    }
}

when accessed through the jquery script it should have written the log informations where i have written logger.info(result) but it seems no log file is created .can someone explain whats the problem ? however the same log file works for all other classes . no issues in that . if exceptions are thrown the log file gets created and log is written. but in this case for logger.info its not happening . i am using Nlog 2.0 with Asp.net 3.5 SP1 .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文