Search code examples
c#sdkgoogle-cloud-logging

Filtering logs using semicolon (":") in Google cloud logging with c# SDK


I am trying to list logs from Google Cloud Logging with a filter using C# SDK:

    var LogClient = LoggingServiceV2Client.Create();
    ListLogEntriesRequest request = new ListLogEntriesRequest
    {
        Filter = "labels.SOME_LABEL: someValue and timestamp >= 2019-05-22T00:00:00Z"
    };
    request.ResourceNames.Add("projects/PROJECT_NAME");
    var res = LogClient.ListLogEntries(request);
    foreach (var r in res)
    {
        Console.WriteLine(r);
    }

I get the following error: StatusCode=InvalidArgument, Detail="Unparseable filter: syntax error at line 1, column 83, token ':'"

Is it possible to use a semicolon in the filter for either a value or as a substring operator ?


Solution

  • It turns out you need to quote the values:

    var LogClient = LoggingServiceV2Client.Create();
    ListLogEntriesRequest request = new ListLogEntriesRequest
    {
        Filter = "labels.SOME_LABEL: \"someValue\" and timestamp >= \"2019-05-22T00:00:00Z\""
    };
    request.ResourceNames.Add("projects/PROJECT_NAME");
    var res = LogClient.ListLogEntries(request);
    foreach (var r in res)
    {
        Console.WriteLine(r);
    }