我想使用 Dotnetnuke 内置的异常处理,它提供了发生错误的详细信息,我尝试了 EventLogController 类来记录错误,但不幸的是它没有记录错误,我也想向用户显示自定义的错误消息。这是我目前用于在事件日志中记录错误的代码。
catch (PageLoadException exc)
{
EventLogController errorController = new EventLogController();
DotNetNuke.Services.Log.EventLog.LogInfo info = new LogInfo();
info.AddProperty("File Name Where Error Occured", exc.FileName);
info.AddProperty("Line number in the file", exc.FileLineNumber.ToString());
info.AddProperty("User logged in when error occured", exc.UserName);
info.AddProperty("Url Of the Page where error occured", exc.AbsoluteURL);
info.AddProperty("Portal ID", exc.PortalID.ToString());
info.AddProperty("Portal Name", exc.PortalName);
info.AddProperty("Method Name", exc.Method);
info.AddProperty("Error Message", exc.Message);
info.AddProperty("Stack Trace", exc.StackTrace);
errorController.AddLog(info);
}
但是它进入.Net的异常捕获,但我无法获得错误的详细信息。
谁能帮助我如何在 Dotnetnuke 的事件日志表中记录错误。并在出现任何异常时向用户显示自定义错误消息。
更新的问题
catch (Exception exc)
{
PageLoadException ex = new PageLoadException();
exc.Message.Insert(0, "File Name: " + ex.FileName);
exc.Message.Insert(1, "Line Number: " + ex.FileLineNumber.ToString());
exc.Message.Insert(2, "User logged in when error occured: " + ex.UserName);
exc.Message.Insert(3, "Url Of the Page where error occured: "+ ex.AbsoluteURL);
exc.Message.Insert(4, "Portal ID: "+ ex.PortalID.ToString());
exc.Message.Insert(5, "Portal Name: " + ex.PortalName);
exc.Message.Insert(6, "Method Name: "+ ex.Method);
exc.Message.Insert(7, "Error Message: " + ex.Message);
exc.Message.Insert(8, "Stack Trace: " + ex.StackTrace);
Exceptions.ProcessModuleLoadException(this, exc);
}
现在有了这个我得到了The page isn't redirecting properly
错误。