public void ListLogEntries() { // Snippet: ListLogEntries(IEnumerable<string>,string,string,string,int?,CallSettings) // Create client LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.Create(); // Initialize request argument(s) IEnumerable <string> projectIds = new List <string>(); string filter = ""; string orderBy = ""; // Make the request IPagedEnumerable <ListLogEntriesResponse, LogEntry> response = loggingServiceV2Client.ListLogEntries(projectIds, filter, orderBy); // Iterate over all response items, lazily performing RPCs as required foreach (LogEntry item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over fixed-sized pages, lazily performing RPCs as required int pageSize = 10; foreach (FixedSizePage <LogEntry> page in response.AsPages().WithFixedSize(pageSize)) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (LogEntry item in page) { Console.WriteLine(item); } } // End snippet }
/// <summary> /// Gets log entries that contain the passed in testId in the log message. Will poll /// and wait for the entries to appear. /// </summary> /// <param name="startTime">The earliest log entry time that will be looked at.</param> /// <param name="testId">The test id to filter log entries on.</param> /// <param name="minEntries">The minimum number of logs entries that should be waited for. /// If minEntries is zero this method will wait the full timeout before checking for the /// entries.</param> private IEnumerable <LogEntry> GetEntries(DateTime startTime, string testId, int minEntries) { TimeSpan totalSleepTime = TimeSpan.Zero; while (totalSleepTime < _timeout) { TimeSpan sleepTime = minEntries > 0 ? _sleepInterval : _timeout; totalSleepTime += sleepTime; Thread.Sleep(sleepTime); // Convert the time to RFC3339 UTC format. string time = XmlConvert.ToString(startTime, XmlDateTimeSerializationMode.Utc); var request = new ListLogEntriesRequest { ResourceNames = { $"projects/{_projectId}" }, Filter = $"timestamp >= \"{time}\"" }; var results = _client.ListLogEntries(request); var entries = results.Where(p => p.TextPayload.Contains(testId)).ToList(); if (minEntries == 0 || entries.Count() >= minEntries) { return(entries); } } return(new List <LogEntry>()); }
private List <LogEntry> ListAllLogEntries() { var request = BuildRequest(_fixtureStart); FileLogger.Log("Starting fetch"); var rawResponses = _client.ListLogEntries(request).AsRawResponses(); var logEntries = new List <LogEntry>(); using (var iterator = rawResponses.GetEnumerator()) { FileLogger.Log("Calling MoveNext"); while (iterator.MoveNext()) { Thread.Sleep(s_delayBetweenPages); logEntries.AddRange(iterator.Current.Entries); } } FileLogger.Log("Finished fetch"); return(logEntries); }
/// <summary> /// Gets log entries that contain the passed in testId in the log message. Will poll /// and wait for the entries to appear. /// </summary> /// <param name="startTime">The earliest log entry time that will be looked at.</param> /// <param name="testId">The test id to filter log entries on.</param> /// <param name="minEntries">The minimum number of logs entries that should be waited for. /// If minEntries is zero this method will wait the full timeout before checking for the /// entries.</param> /// <param name="minSeverity">The minimum severity a log can be.</param> public IEnumerable <LogEntry> GetEntries(DateTime startTime, string testId, int minEntries, LogSeverity minSeverity) { return(GetEntries(minEntries, () => { // Convert the time to RFC3339 UTC format. string time = XmlConvert.ToString(startTime, XmlDateTimeSerializationMode.Utc); var request = new ListLogEntriesRequest { ResourceNames = { $"projects/{_projectId}" }, Filter = $"timestamp >= \"{time}\" AND jsonPayload.message:\"{testId}\" AND severity >= {minSeverity} AND logName=\"projects/{_projectId}/logs/aspnetcore\"", PageSize = 1000, }; return _client.ListLogEntries(request); })); }
/// <summary> /// Gets log entries that contain the passed in testId in the log message. Will poll /// and wait for the entries to appear. /// </summary> /// <param name="startTime">The earliest log entry time that will be looked at.</param> /// <param name="testId">The test id to filter log entries on.</param> /// <param name="minEntries">The minimum number of logs entries that should be waited for. /// If minEntries is zero this method will wait the full timeout before checking for the /// entries.</param> public IEnumerable <LogEntry> GetEntries(DateTime startTime, string testId, int minEntries) { return(GetEntries(minEntries, () => { // Convert the time to RFC3339 UTC format. string time = XmlConvert.ToString(startTime, XmlDateTimeSerializationMode.Utc); var request = new ListLogEntriesRequest { ResourceNames = { $"projects/{_projectId}" }, Filter = $"timestamp >= \"{time}\" AND textPayload:{testId}", PageSize = 1000, }; return _client.ListLogEntries(request); })); }
/// <summary> /// Gets log entries that contain the passed in testId in the log message. Will poll /// and wait for the entries to appear. /// </summary> /// <param name="startTime">The earliest log entry time that will be looked at.</param> /// <param name="testId">The test id to filter log entries on.</param> /// <param name="minEntries">The minimum number of logs entries that should be waited for. /// If minEntries is zero this method will wait the full timeout before checking for the /// entries.</param> public IEnumerable <LogEntry> GetEntries(DateTime startTime, string testId, int minEntries) { return(GetEntries(minEntries, () => { // Convert the time to RFC3339 UTC format. string time = XmlConvert.ToString(startTime, XmlDateTimeSerializationMode.Utc); var request = new ListLogEntriesRequest { ResourceNames = { $"projects/{_projectId}" }, Filter = $"timestamp >= \"{time}\"" }; var results = _client.ListLogEntries(request); return results.Where(p => p.TextPayload.Contains(testId)).ToList(); })); }
/// <summary>Snippet for ListLogEntries</summary> public void ListLogEntries_RequestObject() { // Snippet: ListLogEntries(ListLogEntriesRequest,CallSettings) // Create client LoggingServiceV2Client loggingServiceV2Client = LoggingServiceV2Client.Create(); // Initialize request argument(s) ListLogEntriesRequest request = new ListLogEntriesRequest { ResourceNames = { }, }; // Make the request PagedEnumerable <ListLogEntriesResponse, LogEntry> response = loggingServiceV2Client.ListLogEntries(request); // Iterate over all response items, lazily performing RPCs as required foreach (LogEntry item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over pages (of server-defined size), performing one RPC per page foreach (ListLogEntriesResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (LogEntry item in page) { Console.WriteLine(item); } } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page <LogEntry> singlePage = response.ReadPage(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (LogEntry item in singlePage) { Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary> /// Gets log entries that contain the passed in testId in the log message. Will poll /// and wait for the entries to appear. /// </summary> /// <param name="startTime">The earliest log entry time that will be looked at.</param> /// <param name="testId">The test id to filter log entries on.</param> /// <param name="minEntries">The minimum number of logs entries that should be waited for. /// If minEntries is zero this method will wait the full timeout before checking for the /// entries.</param> /// <param name="minSeverity">The minimum severity a log can be.</param> public IEnumerable <LogEntry> GetEntries(DateTimeOffset startTime, string testId, int minEntries, LogSeverity minSeverity) { return(GetEntries(minEntries, () => { // Convert the time to RFC3339 UTC format. // We substract 5 minutes because on occasion we were polling too fast after startTime // and the backend clock was a little behind, we were getting InvalidArgument. string time = XmlConvert.ToString(startTime.DateTime - TimeSpan.FromMinutes(5), XmlDateTimeSerializationMode.Utc); var request = new ListLogEntriesRequest { ResourceNames = { $"projects/{_projectId}" }, Filter = $"timestamp >= \"{time}\" AND jsonPayload.message:\"{testId}\" AND severity >= {minSeverity} AND logName=\"projects/{_projectId}/logs/aspnetcore\"", PageSize = 1000, }; return _client.ListLogEntries(request); })); }