I'm trying to create a custom webpart. To implement error handling I would like to write to the eventlog. To do so, I'm trying to use the following code;
protected void btnExceptionTester_Click(object sender, EventArgs e)
{
try
{
throw new Exception("this is a test");
}
catch (Exception ex)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
EventLog.WriteEntry("TestWebpart", ex.ToString(), EventLogEntryType.Error);
});
}
}
When I try to execute this code, I receive an sharepoint error page (unhandled exception). When I look in the eventlog, I see the following message; "Requested registry access is not allowed".
I'm runnning (for testing only) under the full trust level. Can someone point out to me what kind of privileges I would need to write to the eventlog? Or is there another approach?
Help greatly appriciated!
I haven't tried writing to the Windows event log but as an alternative you can write to the SharePoint logs in the 12 hive using the following:
Microsoft.Office.Server.Diagnostics.PortalLog.LogString("your message here!");
Hope this helps
Iain
EventLog Entries in SharePoint:
For WebParts Log the errors in the ULS logs which is present in 12 hive.
For SharePoint Application pages, wrtie the errors in the Event Logs.
All other list and Library related errors will be noted down in the ULS logs only.
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With