• DNN学习笔记代码学习:ExceptionLogController 荣


    using System;

    using WebApplication1.Exceptions;

    namespace WebApplication1
    {
     /// <summary>
     /// 设置Log的信息并且把它存储到LoggingProvider对象中。
     /// 是不适在Error筛选器中,选拔Log存储起来,而不对其进行处理?
     /// </summary>
     public class ExceptionLogController : LogController
     {
      /// <summary>
      /// 异常类型。
      /// </summary>
      public enum ExceptionLogType
      {
       GENERAL_EXCEPTION,
       MODULE_LOAD_EXCEPTION,
       PAGE_LOAD_EXCEPTION,
       SCHEDULER_EXCEPTION
      }
      public ExceptionLogController()
      {
       //
       // TODO: 在此处添加构造函数逻辑
       //
      }

      /// <summary>
      /// 设置Log信息。
      /// </summary>
      /// <param name="objException"></param>
      public void AddLog(Exception objException)
      {
       AddLog(objException, ExceptionLogType.GENERAL_EXCEPTION);
      }

      /// <summary>
      /// 根据Log类型,设置Log信息。
      /// </summary>
      /// <param name="objBasePortalException"></param>
      public void AddLog(BasePortalException objBasePortalException)
      {
       switch (objBasePortalException.GetType().Name)
       {
        case "ModuleLoadException":
         AddLog(objBasePortalException, ExceptionLogType.MODULE_LOAD_EXCEPTION);
         break;
        case "PageLoadException":
         AddLog(objBasePortalException, ExceptionLogType.PAGE_LOAD_EXCEPTION);
         break;
        case "SchedulerException":
         AddLog(objBasePortalException, ExceptionLogType.SCHEDULER_EXCEPTION);
         break;
        default:
         AddLog(objBasePortalException, ExceptionLogType.GENERAL_EXCEPTION);
         break;
       }
      }

      /// <summary>
      /// 设置Log信息,并保存到LoggingProvider中
      /// </summary>
      /// <param name="objException"></param>
      /// <param name="LogType"></param>
      public void AddLog(Exception objException, ExceptionLogType LogType)
      {
       // 本类继承自LogController,为什么还需要创建一个LogController对象。
       // 即使不声明LogController对象,照样可以调用AddLog方法啊?
       LogController objLogController = new LogController();
       LogInfo objLogInfo = new LogInfo();
       objLogInfo.LogTypeKey = LogType.ToString();

       // 向LogInfo对象的LogProperties中添加LogDetailInfo对象。在这里就是通过LogProperties扩展LogInfo的例子
       if (LogType == ExceptionLogType.MODULE_LOAD_EXCEPTION)
       {
        ModuleLoadException objModuleLoadException = ( ModuleLoadException)objException;
        objLogInfo.LogProperties.Add(new LogDetailInfo("ModuleId", objModuleLoadException.ModuleId.ToString()));
        objLogInfo.LogProperties.Add(new LogDetailInfo("ModuleDefId", objModuleLoadException.ModuleDefId.ToString()));
        objLogInfo.LogProperties.Add(new LogDetailInfo("FriendlyName", objModuleLoadException.FriendlyName));
        objLogInfo.LogProperties.Add(new LogDetailInfo("ModuleControlSource", objModuleLoadException.ModuleControlSource));
       }

       BasePortalException objBasePortalException = new BasePortalException(objException.ToString(), objException);
       objLogInfo.LogProperties.Add(new LogDetailInfo("AssemblyVersion", objBasePortalException.AssemblyVersion));
       objLogInfo.LogProperties.Add(new LogDetailInfo("Method", objBasePortalException.Method));
       objLogInfo.LogProperties.Add(new LogDetailInfo("FileName", objBasePortalException.FileName));
       objLogInfo.LogProperties.Add(new LogDetailInfo("FileLineNumber", objBasePortalException.FileLineNumber.ToString()));
       objLogInfo.LogProperties.Add(new LogDetailInfo("FileColumnNumber", objBasePortalException.FileColumnNumber.ToString()));
        objLogInfo.LogProperties.Add(new LogDetailInfo("PortalID", objBasePortalException.PortalID.ToString()));
       objLogInfo.LogProperties.Add(new LogDetailInfo("PortalName", objBasePortalException.PortalName));
       objLogInfo.LogProperties.Add(new LogDetailInfo("UserID", objBasePortalException.UserID.ToString()));
       objLogInfo.LogProperties.Add(new LogDetailInfo("UserName", objBasePortalException.UserName));
       objLogInfo.LogProperties.Add(new LogDetailInfo("ActiveTabID", objBasePortalException.ActiveTabID.ToString()));
       objLogInfo.LogProperties.Add(new LogDetailInfo("ActiveTabName", objBasePortalException.ActiveTabName));
       objLogInfo.LogProperties.Add(new LogDetailInfo("AbsoluteURL", objBasePortalException.AbsoluteURL));
       objLogInfo.LogProperties.Add(new LogDetailInfo("AbsoluteURLReferrer", objBasePortalException.AbsoluteURLReferrer));
       objLogInfo.LogProperties.Add(new LogDetailInfo("ExceptionGUID", objBasePortalException.ExceptionGUID));
       objLogInfo.LogProperties.Add(new LogDetailInfo("DefaultDataProvider", objBasePortalException.DefaultDataProvider));
       objLogInfo.LogProperties.Add(new LogDetailInfo("InnerException", objBasePortalException.InnerException.Message));
       objLogInfo.LogProperties.Add(new LogDetailInfo("Message", objBasePortalException.Message));
       objLogInfo.LogProperties.Add(new LogDetailInfo("StackTrace", objBasePortalException.StackTrace));
       objLogInfo.LogProperties.Add(new LogDetailInfo("Source", objBasePortalException.Source));

       objLogInfo.LogPortalID = objBasePortalException.PortalID;

       // 将Log对象存储到(LogController确定的)LoggingProvider对象中
       objLogController.AddLog(objLogInfo);
      }
     }
    }

  • 相关阅读:
    821. 字符的最短距离
    1122. 数组的相对排序
    258. 各位相加
    C++常见问题之二#define使用中的陷阱
    python进阶二_基本数据类型与操作
    DirectX10一变换(三)
    Android中编译工具链的改动----LLVM份量的增加
    DirectX10一矩阵代数(二)
    DirectX10一向量代数(一)
    基于asp.net + easyui框架,一步步学习easyui-datagrid——实现添加、编辑、删除(三)
  • 原文地址:https://www.cnblogs.com/admin11/p/194118.html
Copyright © 2020-2023  润新知