How to: Log an Event for Operations

The following procedure demonstrates how to log messages that are meant for system administrators to the Windows event log and the ULS trace log.

To log an event for operations

  1. In Visual Studio, add a reference to the SharePoint Guidance Library, Microsoft.Practices.SPG.Common.dll. If you are writing a feature receiver, item event receiver, workflow, or anything else that needs to be in the global assembly cache, the Microsoft.Practices.SPG.Common assembly also needs to be in the global assembly cache.

  2. Create an instance of SharePointLogger and invoke the LogToOperations method. Pass an error string and an optional integer event ID to the LogToOperations method. The following code shows how to do this.

    ILogger logger = new SharePointLogger();
    logger.LogToOperations("The current user doesn’t have a PartnerID specified.", 
                           (int) EventLogEventId.PartnerNotFound);
    

Home page on MSDN | Community site