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:
RaygunWebApiClient.ApplicationVersion
in WebApiConfig.Register
, did not work out<target ApplicationVersion="1.1.1.1" />
in nlog.config, this actually works, but its a fixed string, not the current assembly version.<target UseExecutingAssemblyVersion="true" />
in nlog.config, did not workNot 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).
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,