2
votes

The Sharepoint Trace Log Sample given at http://msdn.microsoft.com/en-us/library/aa979522.aspx & explained at /en-us/library/aa979595.aspx does not work in in Sharepoint 2010. Any ideas of how to Write to Trace Log from webpart( non-sandboxed)

1

1 Answers

2
votes

From How to write to ULS Log in SharePoint 2010 from a .NET app?

This has really improved in SP2010. Now you can write to the ULS logs easily even with SharePoint Foundation. All you have to do is this:

SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
diagSvc.WriteTrace( 0, // custom trace id
new SPDiagnosticsCategory("My category", 
TraceSeverity.Monitorable, 
EventSeverity.Error), // create a category
TraceSeverity.Monitorable, // set the logging level of this record
"Writing to the ULS log:  {0}", // custom message
new object[] { "SharePoint rocks!"} // parameters to message );

Works great, but not available in sandboxed solutions...