NLog configured to automatically log all exceptions?

前端 未结 2 882
我在风中等你
我在风中等你 2021-02-05 13:09

Is there a way to configure NLog to automatically log all exceptions my application can send? Currently I am going to all TRY/CATCH blocks and manually adding logging in the CAT

2条回答
  •  醉酒成梦
    2021-02-05 13:31

    For WebApi application you can do this in Global.asax.cs like that

    protected void Application_Error()
    {
        Exception lastException = Server.GetLastError();
        NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
        logger.Fatal(lastException);
    }
    

    MSDN resource

提交回复
热议问题