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)

Syntax

'Declaration
Public Function WriteAuditEvent ( _
    eventId As SPAuditEventType, _
    eventSource As String, _
    xmlData As String _
) As Boolean
'Usage
Dim instance As SPAudit
Dim eventId As SPAuditEventType
Dim eventSource As String
Dim xmlData As String
Dim returnValue As Boolean

returnValue = instance.WriteAuditEvent(eventId, _
    eventSource, xmlData)
public bool WriteAuditEvent(
    SPAuditEventType eventId,
    string eventSource,
    string xmlData
)

Parameters

  • eventSource
    Type: System.String

    The name of the calling application.

Return value

Type: System.Boolean
true in all cases.

Remarks

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.

Examples

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));
oListItem.Audit.WriteAuditEvent(SPAuditEventType.Custom, 
                           "CustomViewAuditEvent",  // SoureName
                           "<myXml>MyData</myXml>"  // Any arbitrary XML data
                           );
Dim oList As SPList = oSiteCollection.Lists(New Guid(ListId))
Dim oListItem As SPListItem = oList.Items.GetItemById(Convert.ToInt32(ItemId))
oListItem.Audit.WriteAuditEvent(SPAuditEventType.Custom, "CustomViewAuditEvent", "<myXml>MyData</myXml>") ' Any arbitrary XML data -  SoureName

See also

Reference

SPAudit class

SPAudit members

WriteAuditEvent overload

Microsoft.SharePoint namespace

Other resources

Item-Level Auditing with SharePoint Server 2007