Advertisement
Guest User

Untitled

a guest
Mar 8th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. namespace ViewSPOLog
  2. {
  3. class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. //Open the Tenant Administration Context with the Tenant Admin Url
  8. using (var tenantContext = new ClientContext("https://yoursite-admin.sharepoint.com/"))
  9. {
  10. //Authenticate with a Tenant Administrator
  11. var passWord = new SecureString();
  12. foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
  13. tenantContext.Credentials = new SharePointOnlineCredentials("admin@yoursite.onmicrosoft.com", passWord);
  14.  
  15. var tenant = new Tenant(tenantContext);
  16.  
  17. var tenantLog = new TenantLog(tenantContext);
  18.  
  19. var dateTimeUTCNow = DateTime.UtcNow;
  20.  
  21. //Get 50 Rows of Tenant Log Entries starting from 5 days ago till now.
  22. var logEntries = tenantLog.GetEntries(dateTimeUTCNow.AddDays(-5), dateTimeUTCNow, 50);
  23.  
  24. //Get 50 Rows of Tenant Log Entries of the specified CorrelationId starting from 5 days ago till now
  25. //var logEntries = tenantLog.GetEntriesByCorrelationId(dateTimeUTCNow.AddDays(-5), dateTimeUTCNow, 50, new Guid("ae2b1e34-12eb-4652-a0db-ce4ab916c74e"));
  26.  
  27. //Get 50 Rows of Tenant Log Entries of the specified Source starting from 5 days ago till now.
  28. //var logEntries = tenantLog.GetEntriesBySource(dateTimeUTCNow.AddDays(-5), dateTimeUTCNow, 50, 1);
  29.  
  30. //Get 50 Rows of Tenant Log Entries of the specified User starting from 5 days ago till now.
  31. //var logEntries = tenantLog.GetEntriesByUser(dateTimeUTCNow.AddDays(-5), dateTimeUTCNow, 50, "admin@yoursite.onmicrosoft.com");
  32.  
  33. tenantContext.Load(logEntries);
  34.  
  35. tenantContext.ExecuteQuery();
  36.  
  37. foreach (TenantLogEntry logEntry in logEntries)
  38. {
  39. Console.WriteLine(string.Format("Timestamp:{0} | Message:{1} | CorrelationId:{2} | Source:{3} | User:{4} | CategoryId:{5}",
  40. logEntry.TimestampUtc, logEntry.Message, logEntry.CorrelationId , logEntry.Source , logEntry.User, logEntry.CategoryId));
  41. }
  42.  
  43. Console.WriteLine("Press Any Key to Exit...");
  44. Console.ReadKey();
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement