1

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.

Abbas
  • 4,948
  • 31
  • 95
  • 161

1 Answers1

1

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.

Chris Hammond
  • 8,873
  • 1
  • 26
  • 34
  • Hi @Chris, thanks for your reply, i could not see lots of options in Exception exc, as compared to those in PageLoadException/ModuleLoadException, how can i get those properties like username, portalname, pageurl etc in Exception exc – Abbas Feb 08 '13 at 16:34
  • You might try adding to the exc.Message property by using exc.Message.Insert method, then use the example lines you used above to insert more information into the message. – Chris Hammond Feb 08 '13 at 17:04
  • hi @Chris can you check my updated question, its still not working – Abbas Feb 08 '13 at 17:18
  • It looks like you can't Insert into the Message, I am looking for another solution – Chris Hammond Feb 08 '13 at 17:58
  • Unfortunately I am not having any luck getting this done :( You might check out the log4net support we have in DNN http://www.dotnetnuke.com/Resources/Wiki/Page/log4net-In-DotNetNuke.aspx – Chris Hammond Feb 08 '13 at 18:47