2

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);

    context.ExecuteQuery();
    site.TrimAuditLog = true;
    site.Audit.AuditFlags = AuditMaskType.All;
    site.Audit.Update();
    context.ExecuteQuery();
}

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

4

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;
            ctx.Load(web);
            ctx.ExecuteQuery();

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

            web.Update();
            ctx.ExecuteQuery();
        }
    }

Hope that helps someone else out :)

  • When in doubt, check the property bag. Thanks, this is awesome. – Derek Gusoff Nov 9 '16 at 16:11
0

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;
targetCtx.ExecuteQuery();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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