Search code examples
.netnlograygun

Raygun does not record the version, when using the NLog Raygun target


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).


Solution

  • 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