Abbas
Abbas

Reputation: 5044

Handling Exception in Dotnetnuke

I want to use Dotnetnuke's built in exception handling which provides detail information of the error occured, i have tried the EventLogController Class to log error, but unfortunately its not logging an error, also i want to display a customized error message to the user. Here's the code i am currently using for Logging Error in Event Log.

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);
}

However it goes in .Net's Exception Catch, but there i could not get detailed information of the error.

Can anyone help me with how could i log error in Dotnetnuke's eventlog table. and also display customized error message to the user when any exception arises.

Updated Question

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);
   }

now with this i am getting The page isn't redirecting properly error.

Upvotes: 1

Views: 1719

Answers (1)

Chris Hammond
Chris Hammond

Reputation: 8943

There are a couple of Methods off the DotNetNuke.Services.Exceptions.Exceptions namespace that allow you to pass in exceptions that will be logged into the EventLog

For example

catch (Exception exc)
        {

            Exceptions.ProcessModuleLoadException(this, exc);
        }

You might try adding information to the Exception (Exc) there before calling the ProcessModuleLoadException to get DNN to handle the error.

The way that exception handling works though, if you aren't a Host/Admin user you get a fairly generic error message when it occurs, this helps prevent security leaks on errors.

Upvotes: 1

Related Questions