使用c#SDK在Google云日志中使用分号(“:”)过滤日志

时间:2019-05-22 05:57:43

标签: c# sdk google-cloud-logging

我正在尝试使用C#SDK使用过滤器列出Google Cloud Logging中的日志:

    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);
    }

我收到以下错误:     StatusCode=InvalidArgument, Detail="Unparseable filter: syntax error at line 1, column 83, token ':'"

是否可以在过滤器中使用分号作为值或子字符串运算符?

1 个答案:

答案 0 :(得分:0)

事实证明您需要引用这些值:

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);
}