I have a created contact form surfaceController, all straight forward and working. I would like to add error logging to handle any exceptions that may occur with the contact form, i.e network goes down, server goes down application fault.
I am new to MVC.net and not sure what best process to use to log errors to troubleshoot. i.e ELMAH or built in Umbraco logging ?
I have made use of Loghelper.Error within my controller, and logs error as expected. what i would like is errors raised within my views to be logged a well i.e syntax error within my razor. I lack experience with MVC .net and not sure how to log any errors from my views.
to the top of your view (after the @inherits statement) and then you can call it like you do in your controller. The @using statement imports a namespace.
Note that while Dan's example will work for logging from your views you won't be able to catch syntax errors like this. Syntax errors will cause an error at compile time so the code in your view won't even get executed when they happen.
Umbraco already writes these errors to the trace log though so you should be able to see them.
Logging errors
Dear Umbraco Team
I have a created contact form surfaceController, all straight forward and working. I would like to add error logging to handle any exceptions that may occur with the contact form, i.e network goes down, server goes down application fault.
I am new to MVC.net and not sure what best process to use to log errors to troubleshoot. i.e ELMAH or built in Umbraco logging ?
Thanks Dibs
I would use the built-in logging (which is built on top of log4net). Just add a reference to
Umbraco.Core.Logging
and then you can use:Where
YourClassName
is the name of the class you want to add to the log that is the calling class, andex
is the exception you wish to log.You can also do:
or
And (shameless promotion!) you can use my custom log viewer extension to view logs from Umbraco - see https://our.umbraco.org/projects/developer-tools/diplo-trace-log-viewer/
Thanks Dan
I have made use of Loghelper.Error within my controller, and logs error as expected. what i would like is errors raised within my views to be logged a well i.e syntax error within my razor. I lack experience with MVC .net and not sure how to log any errors from my views.
Any assistance would be grateful.
Thanks Dibs
Hi,
You just need to add
to the top of your view (after the @inherits statement) and then you can call it like you do in your controller. The @using statement imports a namespace.
Complete example:
Hi Dibs,
Note that while Dan's example will work for logging from your views you won't be able to catch syntax errors like this. Syntax errors will cause an error at compile time so the code in your view won't even get executed when they happen.
Umbraco already writes these errors to the trace log though so you should be able to see them.
Cheers Steven/Dan
Thanks for the advice
Cheers Dibs
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.