Logging Changes in Sitecore Made by Content Authors

May 8, 2015 | Posted by Adam HerrNeckar

Troubleshooting Sitecore data changes can be problematic - especially if versioning and workflows are not utilized, you are contending with a number of minimally trained administrative users, and/or the system relies on multiple data integrations (both inbound and outbound).  Out of the box, Sitecore does not provide full logging of everything that happens within the system - nor would we want it.  However, there are times when creating an audit trail of system changes can be helpful.  Although I have seen various implementations for recording and reporting selected audit detail, I decided to create a new implementation to match my particular needs.

Sitecore's extensible architecture provides us the ability to subscribe to (or hook into) the internal communication bus.  In our case, we want to be offered a chance to log the details of significant activities that may occur while administering Sitecore content.  Specifically, I wanted to record item creations, changes, deletions, etc.

To begin, I created an audit class and simply created methods for responding to the events: "item:creating", "item:saving", "item:deleting".  Unless extended information is logged, the Sitecore AuditFormatter is used to consistently format items in the log.  Since we are only concerned with auditing the content authoring environment (more specifically, the master database), I added checks to make certain the context was appropriate for handling the message.  To minimize the "noise", additional checks were added to ensure we only logged relevant detail; for example, the item saving event inspects field differences to audit user defined (non-system) field changes only - thanks to Marek Musielak for efficient code to determine field differences.  Notice we use the item:saving event to be able to see the before and after of the Sitecore item.  Sitecore provides event arguments to facilitate this.  For a primer on various events, you might find the following link helpful: Using Sitecore Events.

Next, event handlers were added for: "item:copying", "item:moving", "item:renamed", "item:sortorderchanged", "item:templateChanged", and "publish:itemProcessed".  For publishing, operational context and explanations were logged to better understand why Sitecore did what it did.  Conversely, we may not want to see all event details, so optional configuration entries were created to allow them to be disabled/enabled.  For example, auditing sort order changed and item publish events are disabled by default.  Finally, an optional check to prevent duplicate item names via the shell editor (UI) was added to the "item:creating" event.  See the audit code below in Audit.cs...

Audit.cs (click to expand)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
using System.Threading.Tasks;
using Sitecore.Diagnostics;
using Sitecore.Data.Items;
using Sitecore.Events;
using Sitecore.Data.Events;
using Sitecore.SecurityModel;
 
namespace Custom.Diagnostics
{
    public class Audit
    {
 
        #region Configuration Entries
        // The master switch for allowing auditing; To disable Sitecore item auditing add the following to <settings> section within a patch config: <setting name="Audit.Enabled" value="false"/>
        private static readonly bool _auditingEnabled = Sitecore.Configuration.Settings.GetBoolSetting("Audit.Enabled", true);
 
        // Boolean indication if this is a content authoring server (CAS) - which uses the master database.  Content delivery servers use the web database...
        private static readonly bool _isCAS = Sitecore.Sites.SiteManager.GetSite("website").Properties["database"].ToLower() == "master";
 
        // To prevent duplicate item names via the shell editor (UI) add the following to <settings> section within a patch config: <setting name="PreventDuplicateItemNames" value="true"/>
        // Both auditing, and auditing created items must be enabled...
        private static readonly bool _preventDuplicateNames = Sitecore.Configuration.Settings.GetBoolSetting("PreventDuplicateItemNames", false);
 
        // To disable auditing item creations, add the following to <settings> section within a patch config: <setting name="Audit.ItemCreating" value="false"/>
        private static readonly bool _auditItemCreating = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemCreating", true);
 
        // To disable auditing changes to items, add the following to <settings> section within a patch config: <setting name="Audit.ItemSaving" value="false"/>
        private static readonly bool _auditItemSaving = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemSaving", true);
 
        // To disable auditing item deletions, add the following to <settings> section within a patch config: <setting name="Audit.ItemDeleting" value="false"/>
        private static readonly bool _auditItemDeleting = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemDeleting", true);
 
        // To disable auditing copying items, add the following to <settings> section within a patch config: <setting name="Audit.ItemCopying" value="false"/>
        private static readonly bool _auditItemCopying = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemCopying", true);
 
        // To disable auditing item moves, add the following to <settings> section within a patch config: <setting name="Audit.ItemMoving" value="false"/>
        private static readonly bool _auditItemMoving = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemMoving", true);
 
        // To disable auditing renaming of items, add the following to <settings> section within a patch config: <setting name="Audit.ItemRenamed" value="false"/>
        private static readonly bool _auditItemRenamed = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemRenamed", true);
 
        // To enable auditing item sort order changes, add the following to <settings> section within a patch config: <setting name="Audit.ItemSortOrderChanged" value="true"/>
        private static readonly bool _auditItemSortOrderChanged = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemSortOrderChanged", false);
 
        // To disable auditing item template changes, add the following to <settings> section within a patch config: <setting name="Audit.ItemTemplateChanged" value="false"/>
        private static readonly bool _auditItemTemplateChanged = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemTemplateChanged", true);
 
        // To enable auditing item publish processed events, add the following to <settings> section within a patch config: <setting name="Audit.ItemPublished" value="true"/>
        private static readonly bool _auditItemPublished = Sitecore.Configuration.Settings.GetBoolSetting("Audit.ItemPublished", false);
 
        #endregion
 
 
        private static log4net.ILog _log = Sitecore.Diagnostics.LoggerFactory.GetLogger("Sitecore.Diagnostics.Auditing");
 
        public void Log(string message)
        {
            if (_log == null)
                Sitecore.Diagnostics.Log.Audit(message, this);
            else
            {
                string user = (Sitecore.Context.User == null) ? "extranet\\Anonymous" : Sitecore.Context.User.Name;
                _log.Info(string.Format("({0}): {1}", user, message));
            }
        }
 
 
        public static void OnStart()
        {
            if (_isCAS && _auditingEnabled)
            {
                var handler = new Audit();
                if (_auditItemCreating) Sitecore.Events.Event.Subscribe("item:creating", new EventHandler(handler.OnItemCreating));
                if (_auditItemSaving) Sitecore.Events.Event.Subscribe("item:saving", new EventHandler(handler.OnItemSaving));
                if (_auditItemDeleting) Sitecore.Events.Event.Subscribe("item:deleting", new EventHandler(handler.OnItemDeleting));
 
                if (_auditItemCopying) Sitecore.Events.Event.Subscribe("item:copying", new EventHandler(handler.OnItemCopying));
                if (_auditItemMoving) Sitecore.Events.Event.Subscribe("item:moving", new EventHandler(handler.OnItemMoving));
                if (_auditItemRenamed) Sitecore.Events.Event.Subscribe("item:renamed", new EventHandler(handler.OnItemRenamed));
                if (_auditItemSortOrderChanged) Sitecore.Events.Event.Subscribe("item:sortorderchanged", new EventHandler(handler.OnItemSortOrderChanged));
                if (_auditItemTemplateChanged) Sitecore.Events.Event.Subscribe("item:templateChanged", new EventHandler(handler.OnItemTemplateChanged));
 
                if (_auditItemPublished) Sitecore.Events.Event.Subscribe("publish:itemProcessed", new EventHandler(handler.OnItemPublished));
            }
        }
 
        protected void OnItemPublished(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && args is Sitecore.Publishing.Pipelines.PublishItem.ItemProcessedEventArgs && _auditItemPublished)
            {
                using (new SecurityDisabler())
                {
                    Sitecore.Publishing.Pipelines.PublishItem.PublishItemContext context = (args as Sitecore.Publishing.Pipelines.PublishItem.ItemProcessedEventArgs).Context;
 
                    if (context.Result.Operation == Sitecore.Publishing.PublishOperation.Skipped)
                    {
                        try
                        {
                            // If we skipped publishing this item, we only care about logging why if we deliberately tried to republish this item...
                            if (!context.PublishOptions.CompareRevisions && context.PublishOptions.RootItem.ID == context.ItemId)
                            {
                                if (context.PublishHelper.SourceItemExists(context.ItemId))
                                {
                                    Item sourceItem = context.PublishHelper.GetSourceItem(context.ItemId);
                                    Log(string.Format("PUBLISH [{0}]: {1}", context.Result.Operation, AuditFormatter.FormatItem(sourceItem)));
                                }
                                else
                                {
                                    Log(string.Format("PUBLISH [{0}]: {1}", context.Result.Operation, context.ItemId.ToString()));
                                }
                                Log(string.Format("** {0}", context.Result.Explanation));
                            }
                        }
                        catch (Exception)
                        {
                            // We don't need to log - we were skipping this item from getting published anyway
                        }
                    }
                    else
                    {
                        if (context.PublishHelper.SourceItemExists(context.ItemId))
                        {
                            Item sourceItem = context.PublishHelper.GetSourceItem(context.ItemId);
                            Log(string.Format("PUBLISH [{0}]: {1}", context.Result.Operation, AuditFormatter.FormatItem(sourceItem)));
                        }
                        else
                        {
                            Log(string.Format("PUBLISH [{0}]: {1}, msg: {2}", context.Result.Operation, context.ItemId.ToString(), context.Result.Explanation));
                        }
                    }
 
                }
            }
        }
 
        /// <summary>
        /// Responds to Sitecore new item creation, cloning an item, and duplicating an item (either via the UI or API)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">Param index 0 contains the ItemCreatingEventArgs: Contains item ID, name, master and template IDs, parent item</param>
        protected void OnItemCreating(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemCreating)
            {
                using (new SecurityDisabler())
                {
                    ItemCreatingEventArgs arg = Event.ExtractParameter(args, 0) as ItemCreatingEventArgs;
                    Assert.IsTrue(arg != null, "arg != null");
 
                    if ((arg != null) && (Sitecore.Context.Site.Name == "shell") && (_preventDuplicateNames))
                    {
                        foreach (Item currentItem in arg.Parent.GetChildren())
                        {
                            if ((arg.ItemName.Replace(' ', '-').ToLower() == currentItem.Name.ToLower()) && (arg.ItemId != currentItem.ID))
                            {
                                arg.Cancel = true;
                                Sitecore.Context.ClientPage.ClientResponse.Alert("Name \"" + currentItem.Name + "\" is already in use. Please use another name for the item.");
                                return;
                            }
                        }
                    }
 
                    if (arg != null && ShouldAudit(arg.Parent))
                    {
                        Item t = arg.Parent.Database.Items[arg.TemplateId];
                        string templateName = t != null ? t.Name : arg.TemplateId.ToString();
 
                        Log(string.Format("CREATE: {0}:{1}/{2}, id: {3}, template: {4}", arg.Parent.Database.Name, arg.Parent.Paths.Path, arg.ItemName, arg.ItemId.ToString(), templateName));
                    }
                }
            }
        }
 
        /// <summary>
        /// Responds to Sitecore item deletions
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">Param index 0 contains the Item being deleted</param>
        protected void OnItemDeleting(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemDeleting)
            {
                using (new SecurityDisabler())
                {
                    Item item = Event.ExtractParameter(args, 0) as Item;
                    Assert.IsTrue(item != null, "item != null");
 
                    if (item != null && ShouldAudit(item))
                    {
                        Log(string.Format("DELETE: {0}", AuditFormatter.FormatItem(item)));
                    }
                }
            }
        }
 
        /// <summary>
        /// Responds to Sitecore item updates
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">Param index 0 contains the Item being saved</param>
        protected void OnItemSaving(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemSaving)
            {
                using (new SecurityDisabler())
                {
                    Item item = Event.ExtractParameter(args, 0) as Item;
                    Assert.IsTrue(item != null, "item != null");
 
                    if (item != null && ShouldAudit(item))
                    {
                        Item originalItem = item.Database.GetItem(item.ID, item.Language, item.Version);
 
                        var differences = FindDifferences(item, originalItem);
 
                        if (differences.Any())
                        {
                            TimeSpan createdTS = item.Statistics.Updated - item.Statistics.Created;
                            TimeSpan sinceLastSave = item.Statistics.Updated - originalItem.Statistics.Updated;
 
                            if (createdTS.TotalSeconds > 2 && sinceLastSave.TotalSeconds > 2)
                                Log(string.Format("SAVE: {0}", AuditFormatter.FormatItem(item)));
 
                            foreach (string f in differences)
                            {
                                if (string.IsNullOrWhiteSpace(originalItem[f]))
                                    Log(string.Format("** [{0}]: {1}", item.Fields[f].DisplayName, item[f]));
                                else if (originalItem[f].Length <= 40 && item[f].Length <= 40)
                                    Log(string.Format("** [{0}]: {1}, old: {2}", item.Fields[f].DisplayName, item[f], originalItem[f]));
                                else
                                {
                                    Log(string.Format("** [{0}]", item.Fields[f].DisplayName));
                                    Log(string.Format("   -> New: {0}", item[f]));
                                    Log(string.Format("   -> Old: {0}", originalItem[f]));
                                }
                            }
                        }
                    }
                }
            }
        }
 
        /// <summary>
        /// Find non-system fields that have changed
        /// </summary>
        /// <param name="newItem"></param>
        /// <param name="originalItem"></param>
        /// <returns></returns>
        private static List<string> FindDifferences(Item newItem, Item originalItem)
        {
            newItem.Fields.ReadAll();
 
            IEnumerable<string> fieldNames = newItem.Fields.Select(f => f.Name).Where(name => !name.StartsWith("__"));
 
            return fieldNames
              .Where(fieldName => newItem[fieldName] != originalItem[fieldName] && originalItem.Fields[fieldName] != null && newItem.Fields[fieldName].ID == originalItem.Fields[fieldName].ID)
              .ToList();
        }
 
        /// <summary>
        /// Retrieve the current workflow state for the Sitecore item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private static string GetWorkflowState(Item item)
        {
            Sitecore.Workflows.WorkflowInfo info = item.Database.DataManager.GetWorkflowInfo(item);
            return (info != null) ? info.StateID : String.Empty;
        }
 
        private static bool ShouldAudit(Item item)
        {
            return item.Database.Name.ToLower() == "master";
        }
 
        /// <summary>
        /// Responds to Sitecore item copying
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">
        /// Param index 0 contains the Item being copied,
        /// Param index 1 contains the Item Copy destination,
        /// Param index 2 contains the Result item name,
        /// Param index 3 contains the Result item ID,
        /// Param index 4 contains the boolean indication whether it is a recursive copy (including children) or not
        /// </param>
        protected void OnItemCopying(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemCopying)
            {
                using (new SecurityDisabler())
                {
                    Item item = Event.ExtractParameter(args, 0) as Item;
                    Assert.IsTrue(item != null, "item != null");
 
                    if (item != null && ShouldAudit(item))
                    {
                        Item destination = Event.ExtractParameter(args, 1) as Item;
                        string itemName = Event.ExtractParameter(args, 2) as string;
                        Sitecore.Data.ID itemID = Event.ExtractParameter(args, 3) as Sitecore.Data.ID;
                        bool recursive = (bool)Event.ExtractParameter(args, 4);
 
                        if (item.Parent.Paths.Path == destination.Paths.Path && item.Name != itemName)
                            Log(string.Format("DUPLICATE: {0}:{1}, destination: {2}/{3}, id: {4}{5}", item.Database.Name, item.Paths.Path, destination.Paths.Path, itemName, itemID.ToString(), item.Children.Count == 0 ? string.Empty : string.Format(" recursive: {0}", recursive.ToString())));
                        else
                            Log(string.Format("COPY: {0}:{1}, destination: {2}/{3}, id: {4}{5}", item.Database.Name, item.Paths.Path, destination.Paths.Path, itemName, itemID.ToString(), item.Children.Count == 0 ? string.Empty : string.Format(" recursive: {0}", recursive.ToString())));
                    }
                }
            }
        }
 
        /// <summary>
        /// Responds to Sitecore item moving
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">
        /// Param index 0 contains the Item being moved,
        /// Param index 1 contains the ID of the old parent,
        /// Param index 2 contains the ID of the new parent
        /// </param>
        protected void OnItemMoving(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemMoving)
            {
                using (new SecurityDisabler())
                {
                    Item item = Event.ExtractParameter(args, 0) as Item;
                    Assert.IsTrue(item != null, "item != null");
 
                    if (ShouldAudit(item))
                    {
                        Sitecore.Data.ID oldParentID = Event.ExtractParameter(args, 1) as Sitecore.Data.ID;
                        Sitecore.Data.ID newParentID = Event.ExtractParameter(args, 2) as Sitecore.Data.ID;
                        Item oldParent = item.Database.Items[oldParentID];
                        Item newParent = item.Database.Items[newParentID];
 
                        if (item != null && oldParent != null && newParent != null && oldParent.ID != newParent.ID)
                        {
                            Log(string.Format("MOVE: [{0}] from: {1}:{2} to: {3}:{4}", item.Name, oldParent.Database.Name, oldParent.Paths.Path, newParent.Database.Name, newParent.Paths.Path));
                        }
                    }
                }
            }
        }
 
        /// <summary>
        /// Responds to Sitecore item rename
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">
        /// Param index 0 contains the result Item,
        /// Param index 1 contains the Item name prior to being renamed
        /// </param>
        protected void OnItemRenamed(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemRenamed)
            {
                using (new SecurityDisabler())
                {
                    Item item = Event.ExtractParameter(args, 0) as Item;
                    string itemNameBeforeRename = Event.ExtractParameter(args, 1) as string;
 
                    Assert.IsTrue(item != null, "item != null");
 
                    if (item != null && itemNameBeforeRename != item.Name && ShouldAudit(item))
                    {
                        Log(string.Format("RENAME: {0}:{1}/{2}, as: {3}", item.Database.Name, item.Parent.Paths.Path, itemNameBeforeRename, item.Name));
                    }
                }
            }
        }
 
        /// <summary>
        /// Responds to Sitecore item sort order changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">
        /// Param index 0 contains the sorted Item,
        /// Param index 1 contains the Old sortorder value (string)
        /// </param>
        protected void OnItemSortOrderChanged(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemSortOrderChanged)
            {
                using (new SecurityDisabler())
                {
                    Item item = Event.ExtractParameter(args, 0) as Item;
                    string oldSortOrder = Event.ExtractParameter(args, 1) as string;
 
                    Assert.IsTrue(item != null, "item != null");
 
                    if (item != null && ShouldAudit(item))
                    {
                        Log(string.Format("SORT: {0}:{1}, new: {2}, old: {3}", item.Database.Name, item.Paths.Path, item.Appearance.Sortorder, oldSortOrder));
                    }
                }
            }
        }
 
        /// <summary>
        /// Responds to Sitecore item template changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">
        /// Param index 0 contains the ID of the item being changed,
        /// Param index 1 contains the Instance of the datamanager class handling the template
        /// </param>
        protected void OnItemTemplateChanged(object sender, EventArgs args)
        {
            Assert.IsTrue(args != null, "args != null");
            if (args != null && _auditItemDeleting)
            {
                using (new SecurityDisabler())
                {
                    Item item = Event.ExtractParameter(args, 0) as Item;
                    Sitecore.Data.Templates.TemplateChangeList change = Event.ExtractParameter(args, 1) as Sitecore.Data.Templates.TemplateChangeList;
 
                    Assert.IsTrue(item != null, "item != null");
 
                    if (item != null && ShouldAudit(item) && change.Target.ID != change.Source.ID)
                    {
                        Log(string.Format("TEMPLATE CHANGE: {0}:{1}, target: {2}, source: {3}", item.Database.Name, item.Paths.Path, change.Target.Name, change.Source.Name));
                        foreach (Sitecore.Data.Templates.TemplateChangeList.TemplateChange c in change.Changes)
                        {
                            if (c.Action == Sitecore.Data.Templates.TemplateChangeAction.DeleteField)
                                Log(string.Format("** {0}: {1}", c.Action, c.SourceField.Name));
                        }
                    }
                }
            }
        }
    }
}

Subscribing to each event requires configuration settings in a patch config.  Instead, we avoid configuration entries to enable the auditing feature by employing a relatively new approach; adding a PreApplicationStartMethod to the AssemblyInfo.cs.  This allows us to register for the Sitecore events as part of the application initialization process.  See the code below in AssemblyInfo.cs...

AssemblyInfo.cs
1
2
3
using System.Web;
 
[assembly: PreApplicationStartMethod(typeof(Custom.Diagnostics.Audit), "OnStart")]

Logging data pushes to the normal log file, but what if we want to isolate the audit records?  To extend this capability, we added a project reference to the Sitecore.Logging.dll, created a log file appender configuration, and coded its optional use.  See the configuration below in the web.config...

Web.config (click to expand)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<log4net>
  <appender xmu:key="name" name="AuditLogFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
    <file value="$(dataFolder)/logs/audit.log.{date}.txt" />
    <appendToFile value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
    </layout>
    <encoding value="utf-8" />
  </appender>
  <logger xmu:key="name" name="Sitecore.Diagnostics.Auditing" additivity="false">
    <level value="INFO" />
    <appender-ref ref="AuditLogFileAppender" />
  </logger>
</log4net>

And here is an example of the resulting audit log file contents...

Sitecore audit log file

Topics: sitecore cms, Sitecore 7

Want To know more?

Ask how EX Squared can develop your next enterprise web project. Contact us for a fast and free consultation