Write to the event log from the Sharepoint web part

I am trying to create my own website. To implement error handling, I would like to write to the event log. For this, I am 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 get a sharepoint error page (unhandled exception). When I look in the event log, I see the following message; "Requested registry access is not allowed."

I run (for testing only) under a full level of trust. Can someone tell me what privileges I need to write in the event log? Or is there a different approach?

Help to tell a lot!

+5
source share
4 answers

Windows, SharePoint 12 , :

Microsoft.Office.Server.Diagnostics.PortalLog.LogString("your message here!");

,

+8

Update

-:

SPSecurity.RunWithElevatedPrivileges(delegate { EventLog.WriteEntry(...

:

HKLM\SYSTEM\CurrentControlSet\Services\Eventlog\YourWebPartLog

, . ?

+1

EventLog SharePoint:

  • WebParts ULS, 12 .

  • SharePoint .

  • , , ULS.

+1

All Articles