Log errors to SharePoint Log file
Posted by Clayton James on October 29, 2007
I came across this nice code snippet to log exceptions to the default SharePoint log file. (Putting it here for the memory bank).
catch(Exception myException)
{
Microsoft.Office.Server.Diagnostics.PortalLog.LogString(“Exception
Occurred: {0} || {1}”, myException.Message, myException.StackTrace);
}
Sean Fox said
Did somebody not mention the need for wiring a reference to Microsoft.Office.Server? Adding this reference in makes MOSS find my workflow deployment rather distasteful and will thereby reject it?
Halesh said
Hay Sean,
It’s working fine
Sean Fox said
Ope, wait!!! I spoke too soon man. Great method, however. Another good one is to just use the Sharepoint Audit log, which you can run reports against.
Cheers!
Dave said
This works great if and only if you’re using MOSS. If you’re just using WSS, this absolutely will not work, as you will not have the Microsoft.Office assembly.
Error Logging in SharePoint « SPMatt said
[...] (briefly documented in Clayton James’ post Log errors to SharePoint Log file) but that is not available in WSS. There are some examples listed including Eli Robillard’s [...]