I was following this tutorial:
But I got an access denied:
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
using (new SPMonitoredScope("RenderMethod"))
{
writer.Write(DisplayMessage);
DiagnosticsService myULS = DiagnosticsService.Local; // ACCESS DENIED
if (myULS != null)
{
SPDiagnosticsCategory cat = myULS[CategoryId.Provisioning];
string format = "Tracing test of {0} service";
myULS.WriteTrace(1, cat, TraceSeverity.Verbose, format, myULS.TypeName);
myULS.WriteEvent(1, cat, EventSeverity.Information, format, myULS.TypeName);
}
}
}
I tried the following on a console application and the diagSvc is always null
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
);