protected override void ProcessRecord() { ListLogEntriesRequest logEntriesRequest = new ListLogEntriesRequest(); // Set resource to "projects/{Project}" so we will only find log entries in project Project. logEntriesRequest.ResourceNames = new List <string> { $"projects/{Project}" }; string logName = PrefixProjectToLogName(LogName, Project); logEntriesRequest.Filter = ConstructLogFilterString( logName: logName, logSeverity: Severity, selectedType: SelectedResourceType, before: Before, after: After, otherFilter: Filter); do { EntriesResource.ListRequest listLogRequest = Service.Entries.List(logEntriesRequest); ListLogEntriesResponse response = listLogRequest.Execute(); if (response.Entries != null) { foreach (LogEntry logEntry in response.Entries) { WriteObject(logEntry); } } logEntriesRequest.PageToken = response.NextPageToken; }while (!Stopping && logEntriesRequest.PageToken != null); }
protected override void ProcessRecord() { ListLogEntriesRequest logEntriesRequest = new ListLogEntriesRequest(); // Set resource to "projects/{Project}" so we will only find log entries in project Project. logEntriesRequest.ResourceNames = new List <string> { $"projects/{Project}" }; if (ParameterSetName == ParameterSetNames.Filter) { logEntriesRequest.Filter = Filter; } else { string andOp = " AND "; string filterString = ""; if (!string.IsNullOrWhiteSpace(LogName)) { LogName = PrefixProject(LogName, Project); // By setting logName = LogName in the filter, the list request // will only return log entry that belongs to LogName. // Example: logName = "Name of log". filterString = $"logName = '{LogName}'{andOp}".Replace('\'', '"'); } if (Severity.HasValue) { // Example: severity >= ERROR. string severityString = Enum.GetName(typeof(LogSeverity), Severity.Value).ToUpper(); filterString += $"severity = {severityString}{andOp}"; } string selectedType = _dynamicParameters["ResourceType"].Value?.ToString().ToLower(); if (selectedType != null) { // Example: resource.type = "gce_instance". filterString += $"resource.type = '{selectedType}'{andOp}".Replace('\'', '"'); } if (Before.HasValue) { // Example: timestamp <= "2016-06-27T14:40:00-04:00". string beforeTimestamp = XmlConvert.ToString(Before.Value, XmlDateTimeSerializationMode.Local); filterString += $"timestamp <= '{beforeTimestamp}'{andOp}".Replace('\'', '"'); } if (After.HasValue) { // Example: timestamp >= "2016-06-27T14:40:00-04:00". string afterTimestamp = XmlConvert.ToString(After.Value, XmlDateTimeSerializationMode.Local); filterString += $"timestamp >= '{afterTimestamp}'{andOp}".Replace('\'', '"'); } // Strip the "AND " at the end if we have it. if (filterString.EndsWith(andOp)) { logEntriesRequest.Filter = filterString.Substring(0, filterString.Length - andOp.Length); } } do { EntriesResource.ListRequest listLogRequest = Service.Entries.List(logEntriesRequest); ListLogEntriesResponse response = listLogRequest.Execute(); if (response.Entries != null) { foreach (LogEntry logEntry in response.Entries) { WriteObject(logEntry); } } logEntriesRequest.PageToken = response.NextPageToken; }while (!Stopping && logEntriesRequest.PageToken != null); }