Umbraco logging uses log4net, the TYPE should be the type of the object / class you are loggin, usually is used in this way:
//You can specificy the class your are logging LogHelper.Error(typeof(MyClass), "msg", e); //Otherwise, you can use this code, that gets type automatically LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "msg", e);
Thanks for your help. I'm doing my logging within a Razor script so I was unsure what class was being logged. The full script I am testing is:
try
{
client.EnableSsl = true;
client.Send(mail);
<p><strong>Your contact request has been sent. Someone will be in contact shortly</strong></p>
}
catch (Exception ex)
{
//LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Error creating or sending contact mail", ex.InnerException);
umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Error, -1, string.Format("Error creating or sending contact mail: {0}", ex.InnerException));
<p>Error: An error has occured sending your contact details. Please contact us directly using the phone or email listed above.</p>
}
Even the old way of doing things is not recording an entry in the umbracoLog table so I'm wondering if there is an issue with v6.
What is the correct best way for logging custom errors
Hi,
In the past I would do something like:
umbraco.BusinessLogic.Log.Add(...)
which is not getting reported as obsolete and that I should use LogHelper
So I now have
LogHelper.Error<????>(errorMessage, exception)
What should I be using as the type? And is this the recomended way for logging errors?
Cheers
Paul
Maybe check the Umbraco source to see how the LogHelper is used there?
Jeroen
"The friendliest CMS community on the planet" :)
Umbraco logging uses log4net, the TYPE should be the type of the object / class you are loggin, usually is used in this way:
//You can specificy the class your are logging
LogHelper.Error(typeof(MyClass), "msg", e);
//Otherwise, you can use this code, that gets type automatically
LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "msg", e);
Hi Joao,
Thanks for your help. I'm doing my logging within a Razor script so I was unsure what class was being logged. The full script I am testing is:
Even the old way of doing things is not recording an entry in the umbracoLog table so I'm wondering if there is an issue with v6.
Cheers
Paul
Hi Paul,
currently I haven't tried the old api for logging on Umbraco V6, but I've used the new one and it works properly.
So I suggest you to just change your code to use the new API, this simple code will work:
@Joao, v6 now logs using log4net so take a look in /App_data/logs/ for your log entries and not the DB table. Hope that helps.
Really useful post thanks! I would add that to use the v6 log4net LogHelper you need to reference Umbraco.Core.Logging
e.g in a Razor script:
Much less typing!
Darren Ferguson has a great blog post on custom logging here.
Maybe not exactly what you need but certainly useful nonetheless.
OK, answering myself, addding
using Umbraco.Core.Logging;
then you can call:
LogHelper.Info(this.GetType(),string.Format("blblb"));
UPS, this was an answer to: http://our.umbraco.org/forum/developers/api-questions/60739-What-is-the-correct-way-to-write-to-UmbracoTraceLogtxt-in-Umbraco-7
is working on a reply...