I am configuring site auditing via CSOM. Most of this is easily done via code. The one piece I cannot figure out, is how to set the document library where the audit reports are stored before trimming occurs.

This is a sample of how I am setting the audit settings so far.

using (var context = this.sharePointOnlineAuthenticationHelper.GetClientContextWithAccessToken(siteUri.ToString(), siteToken))
    var site = context.Site;
    context.Load(site, s => s.Audit, s => s.AuditLogTrimmingRetention, s => s.TrimAuditLog);

    site.TrimAuditLog = true;
    site.Audit.AuditFlags = AuditMaskType.All;

Can anyone provide any insight on how to set the document library where the audit reports are stored before trimming occurs?

2 Answers 2


A bit late in coming to the party, but in not being able to find the info out there myself thought that I should at least share what I got to work.

The value for the audit report location is stored in a site property which can be easily set via CSOM:

private static void setAuditReportLibrary(String targetSiteUrl)
        using (var ctx = new ClientContext(targetSiteUrl))

            var web = ctx.Web;

            var allProperties = web.AllProperties;
            allProperties["_auditlogreportstoragelocation"] = "/site/LibraryName";


Hope that helps someone else out :)

  • When in doubt, check the property bag. Thanks, this is awesome. Nov 9, 2016 at 16:11

Note: Current site collection should be Enabled custom scripting then only Audit properties updated. Please find below code:

Using (var tentctx = new ClientContext("TenantUrl")) { tentctx.Credentials = new SharePointOnlineCredentials("UserId","pwd"); tentctx.ExecuteQuery(); var tenant = new Tenant(tentctx); if (IsEnable) { tenant.SetSiteProperties(targetUrl, noScriptSite: false); } else { tenant.SetSiteProperties(targetUrl, noScriptSite: true); } tentctx.ExecuteQuery();
// Audit Microsoft.SharePoint.Client.Site site = targetCtx.Site; Audit audit = site.Audit; targetCtx.Load(site);
targetCtx.Load(site.RootWeb); targetCtx.Load(site.RootWeb.AllProperties); targetCtx.Load(audit); targetCtx.ExecuteQuery(); site.RootWeb.AllProperties["_auditlogreportstoragelocation"]= site.ServerRelativeUrl + "/AuditData"; // Enable all auditing is site collection level site.Audit.AuditFlags = Microsoft.SharePoint.Client.AuditMaskType.All; site.Audit.Update(); // Adjust retention time to be 7 days //site.AuditLogTrimmingRetention = 7; site.TrimAuditLog = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.