Web App:

Logging in the Vault Application Framework

This page contains information that is specific to implementing logging within the Vault Application Framework, but does not cover the logging framework in general. Ensure that you read the logging page and others in the section thoroughly.

It is strongly recommended that applications utilize the VAF Extensions library when implemented logging, as this library deals with initializing the logging framework, ensuring that configuration is validated and applied, and rendering the logging configuration to the application’s dashboard.

VAF 22.12

To get started with the new approach, please read the documentation on the VAF upgrade page.

Differences to previous versions

There are three primary differences to the previous logging framework:

  1. There are two required packages: MFiles.VAF.Configuration and MFiles.VAF.Configuration.Logging.NLog. The latter includes NLog-specific implementations.
  2. The namespace MFiles.VaultApplication.Logging has changed to MFiles.VAF.Configuration.Logging.
  3. The string-based logging methods (e.g. Logger.Info("hello {0}", worldVar); or Logger.Info("hello world");) are not supported. Interpolated strings should be used instead (e.g. Logger.Info($"hello {worldVar}" or Logger.Info($"hello world").

Using the VAF Extensions library

There are three steps to using the logging framework with the VAF Extensions library:

  1. Ensure that you are referencing at least version 22.5.27 with nuget. Update your reference if you are targeting an earlier version.
  2. Ensure that you are using the MFiles.VAF.Extensions.ConfigurableVaultApplicationBase<TConfiguration> base class.
  3. Alter your configuration to inherit from MFiles.VAF.Extensions.Configuration.ConfigurationBase (or alternative; see below), to expose the logging configuration.

Once done, you can then use the logger from within your code:

Remember to enable logging in your application’s configuration in M-Files Admin, otherwise no logs will be generated!

Exposing logging configuration

The easiest way to expose the logging configuration is to ensure that your top-level configuration class inherits from the class in the VAF Extensions library. If you have done this then the logging configuration should be visible, and logging should function if enabled:

In some situations you may not want to expose the logging configuration in this way, or may wish to control how the logging configuration is displayed. You can optionally choose to instead implement MFiles.VAF.Extensions.Configuration.IConfigurationWithLoggingConfiguration yourself in your top-level configuration class:

Note that the logging configuration itself could be held anywhere in your configuration, provided that the top-level class implements the above interface, and the GetLoggingConfiguration returns the configured value.

Implementing the functionality yourself

If you cannot use the VAF Extensions, then using the logging framework from a plain Vault Application is also possible. The example below uses the VAF 2.3 and older versions of the framework may need some additional changes: