Using the Sitecore Audit Log

I guess your code contains just as many log messages as my code does:

  // lots of stuff going on here...
catch (Exception ex)
  Sitecore.Diagnostics.Log.Error("Some great error message: " + ex.Message, this);
  // more exception handling here...

And the exception is written to the log:

6636 13:35:42 ERROR Some great error message: blahblahblah

In previous versions, the Audit log was a seperate log. But now it’s all handled by Apache Log4Net. So writing to the audit log is similar to writing to the log. The following line:

Sitecore.Diagnostics.Log.Audit("DamForSitecore:RemoveAssetFromCache. AssetID=" + assetID, this);

Produces the following log line:

3360 13:56:27 INFO  AUDIT (sitecore\admin): DamForSitecore:RemoveAssetFromCache. AssetID=4848

You can use the AuditFormatter to format items and fields so they appear with the same pattern for all items and fields in the log.
The following line:

Sitecore.Diagnostics.Log.Audit(this, "Do stuff {0}", new[] {AuditFormatter.FormatItem(Sitecore.Context.Item)});

Produces the following log line:

3360 14:06:18 INFO  AUDIT (sitecore\admin): Do stuff: master:/sitecore/content/Home, language: da, version: 2, id: {110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}

Other articles regarding the subject:


About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in c#, Sitecore 6 and tagged , , , , . Bookmark the permalink.

1 Response to Using the Sitecore Audit Log

  1. Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.