MindscapeHQ / serilog-sinks-raygun

A Serilog sink that writes events to Raygun
Apache License 2.0
11 stars 20 forks source link

Getting the version from the Assembly does not seem to work #48

Closed erik-kallen closed 2 years ago

erik-kallen commented 2 years ago

I have the following Serilog config:

  "Serilog": {
    "Using": [ "Serilog.Sinks.Raygun", "Serilog.Sinks.File" ],
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "Microsoft": "Warning",
        "System.Net.Http.HttpClient": "Warning"
      }
    },
    "WriteTo": [
      {
        "Name": "Raygun",
        "Args": {
          "applicationKey": "<secret>"
        }
      },
      {
        "Name": "File",
        "Args": {
          "path": "./logs/log.txt",
          "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level:w3}] {Scope} {Message}{NewLine}{Exception}"
        }
      }
    ],
    "Enrich": [ "WithHttpDataForRaygun" ]
  }

This works, but the version is reported in the RayGun UI as "Not supplied". The documentation says that the assembly version of the entry assembly should be used by default, but this does not happen.

erik-kallen commented 2 years ago

Appears that I managed to misread the documentation. If I add the ApplicationVersion property, it is sent as expected.

Sorry

QuantumNightmare commented 2 years ago

Not a problem @erik-kallen. Apologies for missing your question. Indeed by default this SDK will attempt to get the version of the entry assembly, but in some frameworks it can't pick it up. To clarify, have you resorted to specifying the version manually via the ApplicationVersion data field? Feel free to send a code snippet of what you've done if you don't mind. If you're doing this by fetching the version of the entry assembly, then that would make me wonder why the SDK isn't picking that up by default.

erik-kallen commented 2 years ago

We are using .net 5, and it did not manage to automatically get the version from the input assembly. What I ended up doing was

.UseSerilog((builder, config) =>
{
    config.ReadFrom.Configuration(builder.Configuration)
        .Enrich.WithProperty("ApplicationVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString())
        .Enrich.FromLogContext();
    })
}

and that worked

QuantumNightmare commented 2 years ago

Thanks for the additional details and code snippet, that's much appreciated. I've noted down to explore if this could be picked up automatically in .NET 5+ but don't have a time frame of when this could be done.

erik-kallen commented 2 years ago

It could also be a good idea to amend the documentation with the information that post data will not be sent unless code like the following is added to the startup:

app.Use((context, next) =>
{
    context.Request.EnableBuffering();
    return next();
});