Skip to content

[Question] Elastic.CommonSchema.NLog and System.Text.Json with source generation #525

@markdsitu

Description

@markdsitu

Hi, we are planning to use Elastic.CommonSchema.NLog package in our C# Lambda which is performing logging using NLog already. The code package is produced with AOT compilation and we are using source generation for System.Text.Json for maximum AOT compatibility.

When I plugged EcsLayout into my console logs I started getting these errors.

JsonTypeInfo metadata for type 'System.DateTimeOffset' was not provided by TypeInfoResolver of type '<null>'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.

With stack traces like this:

   at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
   at System.Text.Json.JsonSerializerOptions.GetConverterInternal(Type typeToConvert)
   at Elastic.CommonSchema.Serialization.EcsJsonConfiguration..cctor() in C:\stash\ecs-dotnet\src\Elastic.CommonSchema\Serialization\JsonConfiguration.cs:line 39

I have a couple of questions.

  1. Is there some configuration currently I can perform to make this work?
  2. If not, could this be made to work in Elastic.CommonSchema.NLog?

I've pulled the ecs-dotnet repo and made local changes directly. I could get it to work with my use case with the following changes.

Image Image

However I don't understand enough of how everything hangs together to know if this will work for all use-cases.

Appreciate your assistance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions