SPAudit.WriteAuditEvent method (SPAuditEventType, String, String)

Writes a record about an event to the SharePoint database.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public bool WriteAuditEvent(
	SPAuditEventType eventId,
	string eventSource,
	string xmlData


Type: Microsoft.SharePoint.SPAuditEventType

The kind of event being recorded.

Type: System.String

The name of the calling application.

Type: System.String

The information about the event.

Return value

Type: System.Boolean
true in all cases.

Use this method to write records of custom event types or custom versions of existing event types. Pass Custom for eventID when you are writing a custom event. (If you have more than one type of custom event and you want to distinguish them in audit reports, use the WriteAuditEvent(String, String, String) overload of the method.) When your event resembles one of the existing SPAuditEventType objects and you want it included in audit reports of that type of event, pass the appropriate SPAuditEventType value for eventID.

Pass the name of your SharePoint solution as eventSource. Optionally, pass up to 4000 characters of additional information about the event as xmlData.

You can use any XML schema you want to format xmlData, or you can use undefined XML. However, when you are including data that is essentially the same as event data that SharePoint Foundation uses in its built-in events, reading and processing your database records is easier if you use the same tags. For example, if your event data refers to an object other than the one on which the event was raised, use the pattern <RelatedItem><Id>GUID_of_other_object</Id><Relationship>some_relationship</Relationship></RelatedItem>, which is similar to what SharePoint Foundation uses for ChildDelete events. See the topic for SPAuditEntry.EventData for more information on the XML tags that SharePoint Foundation uses.

The following example (from Item-Level Auditing with SharePoint Server 2007) shows this method in use.

SPList oList = oSiteCollection.Lists[new Guid(ListId)];
SPListItem oListItem = oList.Items.GetItemById(Convert.ToInt32(ItemId));
                           "CustomViewAuditEvent",  // SoureName
                           "<myXml>MyData</myXml>"  // Any arbitrary XML data