Oracle Cloud Logging's log ingestion using OCI .Net SDK. Error: "Unable to process JSON input"

Oracle Cloud Logging's log ingestion using OCI .Net SDK. Error: "Unable to process JSON input"

我正在尝试使用 OCI 的日志摄取 API 将一些日志放入自定义(应用程序)日志中,但我一直收到这条非常模糊的错误消息:“无法处理 JSON 输入”。 尽管缺少 .Net SDK (outside of class descriptions), I managed to create a PutLogs request in .net 5. Confronting the generated HTTP request with the OCI's API documentation (which is good) 的文档,但我没有发现任何问题,但服务器一直返回错误。

这是重现问题的简单代码:

using Oci.Common;
using Oci.Common.Auth;
using Oci.Common.Model;
using Oci.LoggingingestionService;
using Oci.LoggingingestionService.Models;
using Oci.LoggingingestionService.Requests;

using System;
using System.Collections.Generic;
using System.Security;

namespace LogIngestionTest
{
    class Program
    {
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            var client = new LoggingClient(new SimpleAuthenticationDetailsProvider
            {
                TenantId = "ocid1.tenancy.oc1..(...)",
                UserId = "ocid1.user.oc1..(...)",
                Fingerprint = "3a:82:(...)",
                Region = Region.FromRegionId("sa-saopaulo-1"),
                PrivateKeySupplier = new FilePrivateKeySupplier(@".\oracle\dev.private.pem", new SecureString())
            });

            var putLogsRequest = new PutLogsRequest
            {
                LogId = "ocid1.log.oc1.sa-saopaulo-1.(...)",
                PutLogsDetails = new PutLogsDetails
                {
                    Specversion = "1.0",
                    LogEntryBatches = new List<LogEntryBatch>
                    {
                        new LogEntryBatch
                        {
                            Source = "ProductionIdentityServer",
                            Defaultlogentrytime = DateTime.Now,
                            Type = "AccessLogs",
                            Entries = new List<LogEntry>
                            {
                                new LogEntry
                                {
                                    Id = Guid.NewGuid().ToString(),
                                    Data = @"{ ""Message"": ""User not found."" }"
                                }
                            }
                        }
                    }
                }
            };

            try
            {
                var response = await client.PutLogs(putLogsRequest);
                Console.WriteLine($"Success! ({response.OpcRequestId})");
            }
            catch (OciException ex)
            {
                Console.WriteLine(
                    $"Error: {ex.Message}\n" +
                    $"Service Code: {ex.ServiceCode}\n" +
                    $"opc-request-id: {ex.OpcRequestId}"
                );
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}\n");
                throw;
            }
        }
    }
}

这是生成的 HTTP 请求正文:

{
  "specversion": "1.0",
  "logEntryBatches": [
    {
      "entries": [
        {
          "data": "{ \"Message\": \"User not found.\" }",
          "id": "4da4f080-35bb-44e3-9713-df87dfd07878"
        }
      ],
      "source": "ProductionIdentityServer",
      "type": "AccessLogs",
      "defaultlogentrytime": "2020-12-01T10:08:30.5669775-03:00"
    }
  ]
}

以及服务器的响应:

{
  "code": "InvalidParameter",
  "message": "Unable to process JSON input"
}

此问题已在 dotnet sdk 8.0.0 版本中修复。您能否将您的 csproj 中使用的版本更新为 8.0.0 并重试?