Skip to content

AssemblyVersion Layout Renderer

ittegrat edited this page Jul 20, 2023 · 20 revisions

Renders assembly version information from the entry assembly or a named assembly.

Platforms Supported: All

Introduced for ASP.NET / ASP.NET Core in NLog.Web 4.5.0 / NLog.Web.AspNetCore 4.4.0.

Configuration Syntax

${assembly-version:name=string:type=Enum:format=string}

Parameters

  • Name - Display name of the assembly to retrieve a version from, as determined by its FullName property. The assembly will be loaded if needed. If not specified, will use the entry assembly (this did not function correctly for .NET Core until NLog.Web.AspNetCore 4.6). Introduced in NLog 4.3.7.

  • Type - Type of the assembly version value to retrieve. Default: Assembly.

    Introduced with NLog v4.5.

    Introduced for ASP.NET with NLog.Web / NLog.Web.AspNetCore v4.6.

    Possible enum values:

    • Assembly - Assembly version. Value for AssemblyVersion attribute.

      Note: UWP earlier than .NET Standard 1.5 uses value for ApplicationVersion

    • File - File version. Value for AssemblyFileVersion attribute.

      Notes:

      • UWP earlier than .NET Standard 1.5 uses Assembly instead unless a value is given for the name parameter
    • Informational - Product Version extracted from AssemblyInformationalVersion attribute.

      Notes:

      • UWP earlier than .NET Standard 1.5 uses Assembly instead unless a value is given for the name parameter
  • Format - Custom format of the assembly version output. Default: major.minor.build.revision Supported placeholders are 'major', 'minor', 'build' and 'revision'. The default .NET template for version numbers is 'major.minor.build.revision'. See https://docs.microsoft.com/en-gb/dotnet/api/system.version?view=netframework-4.7.2#remarks for details.

    Introduced with NLog 4.6

  • Default - Custom value to output when assembly version cannot be found, is empty or matches 0.0.0.0

    Introduced with NLog 5.0.2

Remarks

As this layout renderer uses reflection and version information is unlikely to change during application execution, it is recommended to use it in conjunction with the CachedLayoutRendererWrapper. The entry assembly can't be found in some cases e.g. ASP.NET, unit tests, etc.

Examples

Retrieve assembly version for entry assembly:

${assembly-version}

Retrieve assembly version for assembly name NLogAutloadExtension:

${assembly-version:NLogAutloadExtension}

Retrieve file version for entry assembly:

${assembly-version:type=File}

Retrieve informational version for assembly name NLogAutloadExtension:

${assembly-version:name=NLogAutloadExtension:type=Informational}
Clone this wiki locally