Domanda

I want to create multiple entries of SPAudit for test it before use it in real environment. I supposed that I just can open a web many times and generate as many entries as I want. So i wrote this:

using System;
using Microsoft.SharePoint;

namespace Audit.Tests
{
    internal class Program
    {
        private static void Main()
        {
            const string siteURL = "http://somesite";
            const int n = 50000;
            const int k = n/100;
            for (int i = 0; i < n; i++)
            {
                using (SPSite siteCollection = new SPSite(siteURL))
                {
                    using (var web = siteCollection.OpenWeb())
                    {
                        if (i%k == 0)
                            Console.WriteLine("Completed {0}%", i*100/n);
                    }
                }
            }
        }
    }
}

but no audit entries seems to be created.

È stato utile?

Soluzione

Opening a web does not cause an entry to be created in the SharePoint audit log. Assuming you have "view" auditing turned on at the web or site collection level that will log views (opens) of documents, list items, and item properties.

Extend your code above to open a file...i.e. SPFile.OpenBinary. That will cause audit entries to be created.

Altri suggerimenti

your doing nothing to the web object? did you mean that you want to write to the web audit log event?

using System;
using Microsoft.SharePoint;

namespace Audit.Tests
{
    internal class Program
    {
        private static void Main()
        {
            const string siteURL = "http://somesite";
            const int n = 50000;
            const int k = n/100;
            for (int i = 0; i < n; i++)
            {
                using (SPSite siteCollection = new SPSite(siteURL))
                {
                    using (var web = siteCollection.OpenWeb())
                    {
                        if (i%k == 0)
                        {
                            web.Audit.WriteAuditEvent(SPAuditEventType.Custom, "AuditEvent", "");

                            Console.WriteLine("Completed {0}%", i*100/n);
                        }
                    }
                }
            }
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top