简体   繁体   English

DNN(DotNetNuke)模块异常未记录

[英]DNN (DotNetNuke) module exceptions not logging

I have a customer's DNN site with a custom module that's having issues with module error logging. 我有一个客户的DNN站点,其中包含一个自定义模块,该模块存在模块错误日志记录问题。 The site was upgraded to version 7.4 from 6.2 and now to version 9.0. 该站点已从6.2升级到7.4版,现在又升级到9.0版。 Module exceptions no longer appear in Admin / Host Events since the upgrade to 7.4. 自从升级到7.4版以来,模块异常不再出现在“管理员/主机事件”中。 It appears module exception logging was changed in DNN 7.4 as explained here . 似乎模块异常日志记录已在DNN 7.4中更改, 如此处所述 This is the code that worked before but now nothing gets logged; 这是以前工作过的代码,但现在没有任何记录。

Test object: 测试对象:

public class foo
{
    public int id { get; set; }
    public string bar { get; set; }
}

Test webapi Controller: 测试webapi控制器:

[DnnAuthorize]
public class MyCustomModuleController : DnnApiController
{
    private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(MyCustomModuleController));


    [HttpGet]
    public HttpResponseMessage GetFoo(int id)
    {
        try
        {
            foo test = null;
            var bar = test.bar; //will throw null exception

            ...

        }
        catch (Exception ex)
        {
            Logger.Error(ex); //no log entries in db since ver. 7.4
            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server error");
        }
    }

Is there a setting that I should enable or is there a new way of logging events? 是否有我应该启用的设置?是否有记录事件的新方法?

It is my understanding that DotNetNuke.Instrumentation.GetLogger() returns the logging object for doing the Log4Net logging to file appender logs stored in: /Portals/_default/Logs. 据我了解,DotNetNuke.Instrumentation.GetLogger()返回将Log4Net日志记录到存储在/ Portals / _default / Logs中的文件追加程序日志的日志记录对象。 You can also view them from Host > Host Settings > Logs. 您也可以从主机>主机设置>日志中查看它们。

Normally, you would add to your class by setting it up in a constructor and calling the .Error()/.ErrorFormat(), .Warn()/.WarnFormat(), etc functions to append an error or information message to the logging file. 通常,您可以通过在构造函数中进行设置并调用.Error()/。ErrorFormat()、. Warn()/。WarnFormat()等函数来添加类,以将错误或信息消息附加到日志记录中文件。

public class MyCustomModuleController : DnnApiController
{
    private DotNetNuke.Instrumentation.ILog Logger { get; set; }

    public MyCustomModuleController()
    {
        Logger = DotNetNuke.Instrumentation.LoggerSource.Instance.GetLogger(this.GetType());
    }

    public HttpResponseMessage GetFoo(int id)
    {
        try
        {
           ...
        }
        catch (Exception ex)
        {
            Logger.Error(ex); 
        }
    }
}

The other logging technique available is using the DotNetNuke.Services.Exceptions to log the exception to the database. 可用的另一种日志记录技术是使用DotNetNuke.Services.Exceptions将异常记录到数据库中。 These errors get added to the EventLog and Exceptions tables. 这些错误将添加到EventLog和Exceptions表中。

public class MyCustomModuleController : DnnApiController
{   
    public HttpResponseMessage GetFoo(int id)
    {
        try
        {
           ...
        }
        catch (Exception ex)
        {
            DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); 
        }
    }
}

It is possible that DNN disconnected the Log4Net process with the EventLog. DNN可能会与EventLog断开Log4Net进程的连接。 I can't remember how it worked back in version 6. 我不记得它在版本6中是如何工作的。

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

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