I guess your code contains just as many log messages as my code does:
try { // 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:
Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog