views:

443

answers:

2

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)

A: 

I am also using the sample given on MSDN, it is working fine with MOSS 2007 and not working with Sharepoint 2010. Any help on this is appreciated.

Lalitha
+1  A: 

From http://www.sharepointoverflow.com/questions/2057/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...

Hasan Khan