0

On a .NET Framework WebAPI service, using Raygun and NLog. When an exception happens, Raygun tracks the correct version of the executing assembly. But when the error is reported via NLog Raygun target, it only says Could not find value for entry assembly and version type File.

What I already tried to fix this:

  1. update all packages
  2. set RaygunWebApiClient.ApplicationVersion in WebApiConfig.Register, did not work out
  3. set <target ApplicationVersion="1.1.1.1" /> in nlog.config, this actually works, but its a fixed string, not the current assembly version.
  4. set <target UseExecutingAssemblyVersion="true" /> in nlog.config, did not work
  5. set AssemblyVersion, FileVersion and Version in .csproj for all (.NET Standard) sub projects, did not work out

Not sure, what else could help. When I call Assembly.GetExecutingAssembly().GetName().Version at the place, where Logger.Error is called, it returns the correct version (but it is still not recorded).

Hinek
  • 9,519
  • 12
  • 52
  • 74

1 Answers1

1

NLog.Raygun-nuget-package supports NLog Layout for the target-option ApplicationVersion, so you can do this:

<target type="Raygun" name="RaygunTarget" 
        applicationVersion="${gdc:item=AppVersion}" />

Where you can provide the NLog GDC value at runtime like this:

string appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
NLog.GlobalDiagnosticsContext.Set("AppVersion", appVersion);

You can also consider using NLog ${assembly-version} instead of using NLog GDC. Just have to specify the Assembly Name to extract the version-info from (If Entry-Assembly version is not working).

Notice UseExecutingAssemblyVersion in NLog.Raygun means resolve assembly-version automatically from System.Reflection.Assembly.GetEntryAssembly(). I guess the option-name is misleading,

See also: https://github.com/MindscapeHQ/NLog.Raygun

Rolf Kristensen
  • 17,785
  • 1
  • 51
  • 70
  • Thank you so much, I went with NLog assembly-version and it works, when I specify the assembly name of the entry assembly like this `${assembly-version:assemblyname}`. When I only use `${assembly-version}`, it should return the version of the entry assembly, but it will save "Could not find value for entry assembly and version type Assembly" to the Version field (notice it now says "Assembly" instead of "File"). Curious, why it isn't able to find the entry assembly, but specifying the name will definitely work for me. – Hinek Apr 21 '23 at 06:57