Hide

YetaWF Documentation

Display
Print

YetaWF.LoggingDataProvider Package

Overview

Implements logging services for YetaWF (for all sites within one YetaWF instance) using PostgreSQL, SQL, NLog, flat file or .NET logging.

The log can be accessed using Admin > Dashboard > Logging (standard YetaWF site).

AppSettings.json Syntax

{
  . . .
  "Application":
    . . .
    "P": {
      "Logging": {
        "Assembly": "YetaWF.LoggingDataProvider",
        "Type": "type-implementing-logging",
        "MinLevel": minimum-log-level
      }
      . . .
      "YetaWF_Logging: {
        "IOMode": "SQL"|"PostgreSQL"|"File"|"NLog",

        // IOMode SQL
        "SQLDbo": "dbo",
        "SQLConnect": "Data Source=....;Initial Catalog=....;User ID=....;Password=....",

        // IOMode PostgreSQL
        "PostgreSQLSchema": "public",
        "PostgreSQLConnect": "Host=...;Port=5432;Username=...;Password=...;Database=...",

        // IOMode NLog
        "NLogMessageFormat": null|"json",
        "NLogMessageEvent": {true|false}
      }

Application.P.Logging

Defines the assembly (Assembly) that implements logging services. The specified Type type-implementing-logging is instantiated during application startup to initialize the assembly and the associated logging services. The package YetaWF.LoggingDataProvider is provided with YetaWF and implements all logging services.

The detail level logged is defined using the Application.P.Logging.MinLevel key. Currently 0 defines informational messages, 50 are warnings and >= 99 are errors. For production sites, it is recommended to use the value 50, otherwise too much unnecessary data is logged.

Supported logging targets are Microsoft (.NET) logging, NLog, PostgreSQL table, SQL table, or a flat file. NLog can be used to log to additional targets, including external logging services.

The desired logging targets are enabled by setting the Application.P.Logging.Type value:

ArgumentDescription
YetaWF.Modules.LoggingDataProvider.DataProvider.MSLog.LogRecordDataProviderUses .NET logging. This can be used for console logging, typically in Docker containers.
YetaWF.Modules.Logging.DataProvider.NLogProvider.LogRecordDataProviderUses NLog as logging target. NLog.config and NLog.Prod.config (for deployed build) must be provided in the folder ./Webwsite/Data to configure NLog. When deploying the site, the file NLog.Prod.config is deployed as NLog.config to the target site.
YetaWF.Modules.Logging.DataProvider.PostgreSQL.LogRecordDataProviderUses PostgreSQL as logging target. The target PostgreSQL table is defined by the YetaWF.LoggingDataProvider package entries in AppSettings.json.
YetaWF.Modules.Logging.DataProvider.SQL.LogRecordDataProviderUses SQL as logging target. The target SQL table is defined by the YetaWF.LoggingDataProvider package entries in AppSettings.json.
YetaWF.Modules.Logging.DataProvider.File.LogRecordDataProviderUses a flat file as logging target. The log file is located at ./Website/Data/DataFolder/YetaWF_Logging/LogFile.txt.

P.Logging.MinLevel defines the minimum level that is recorded to the log file and corresponds to a value defined by YetaWF.Core.Log.Logging.LevelEnum.

Application.P.YetaWF_Logging

The Application.P.YetaWF_Logging section is used to customize the logging providers used. It is used for the NLog, PostgreSQL, SQL and File log record data providers. It is ignored for the MSLog (.NET) logging data provider.

PostgreSQL Provider

To enable logging using PostgreSQL the following has to be present in the YetaWF site's AppSettings.json file:

    "P": {
      . . .
      "Logging": {
        . . .
        "Assembly": "YetaWF.LoggingDataProvider",
        "Type": "YetaWF.Modules.Logging.DataProvider.PostgreSQL.LogRecordDataProvider",
        "MinLevel": "0",

This defines the class YetaWF.Modules.Logging.DataProvider.PostgreSQL.LogRecordDataProvider as the logging provider.

Logging to a PostgreSQL database table using the PostgreSQL provider is synchronous. For async logging, the NLog provider should be used instead.

The PostgreSQL database is defined using the YetaWF site's AppSettings.json file. The table used for logging is named YetaWF_Logging.

    "P": {
      . . .
      "YetaWF_Logging": {
        . . .
        "IOMode": "PostgreSQL"
        "PostgreSQLSchema": "public"
        "PostgreSQLConnect": "Host=...;Port=5432;Username=...;Password=...;Database=..."
SQL Provider

To enable logging using SQL the following has to be present in the YetaWF site's AppSettings.json file:

    "P": {
      . . .
      "Logging": {
        . . .
        "Assembly": "YetaWF.LoggingDataProvider",
        "Type": "YetaWF.Modules.Logging.DataProvider.SQL.LogRecordDataProvider",
        "MinLevel": "0",

This defines the class YetaWF.Modules.Logging.DataProvider.SQL.LogRecordDataProvider as the logging provider.

Logging to a SQL database table using the SQL provider is synchronous. For async logging, the NLog provider should be used instead.

The SQL database is defined using the YetaWF site's AppSettings.json file. The table used for logging is named YetaWF_Logging.

    "P": {
      . . .
      "YetaWF_Logging": {
        . . .
        "IOMode": "SQL"
        "SQLDbo": "dbo"
        "SQLConnect": "Data Source=....;Initial Catalog=....;User ID=....;Password=...."
File Provider

To enable logging using a flat file the following has to be present in the YetaWF site's AppSettings.json file:

    "P": {
      . . .
      "Logging": {
        . . .
        "Assembly": "YetaWF.LoggingDataProvider",
        "Type": "YetaWF.Modules.Logging.DataProvider.File.LogRecordDataProvider",
        "MinLevel": "0",

This defines the class YetaWF.Modules.Logging.DataProvider.File.LogRecordDataProvider as the logging provider.

The following is required for file I/O.

    "P": {
      . . .
      "YetaWF_Logging": {
        . . .
        "IOMode": "File",

The detail level logged is defined using the Application.P.Logging.MinLevel key. Currently 0 defines informational messages, 50 are warnings and >= 99 are errors. For production sites, it is recommended to use the value 50, otherwise too much unnecessary data is logged.

NLog Provider

To enable logging using NLog the following has to be present in the YetaWF site's AppSettings.json file:

    "P": {
      . . .
      "Logging": {
        . . .
        "Assembly": "YetaWF.LoggingDataProvider",
        "Type": "YetaWF.Modules.Logging.DataProvider.NLogProvider.LogRecordDataProvider",
        "MinLevel": "0",

This defines the class YetaWF.Modules.Logging.DataProvider.NLogProvider.LogRecordDataProvider as the logging provider.

To use NLog logging without using the YetaWFDB target (see below), the Application.P.YetaWF_Logging entry should be defined as follows:

    "P": {
      . . .
      "YetaWF_Logging": {
        "NLogMessageFormat": null,
        "NLogMessageEvent": false
      },

The detail level logged is defined using the Application.P.Logging.MinLevel key. Currently 0 defines informational messages, 50 are warnings and >= 99 are errors. For production sites, it is recommended to use the value 50, otherwise too much unnecessary data is logged.

NLog.config

An NLog.config file must be added in the sites ./Data folder with NLog configuration settings. YetaWF provides a default NLog.config file which can be customized.

YetaWFDB Target

YetaWF implements an NLog target named "YetaWFDB" which logs to the SQL table YetaWF_Logging. The sample NLog.config file provided with YetaWF shows how to use the YetaWFDB target.

The following settings are required to use SQL logging with NLog. This takes advantage of NLog's async logging. The log can be accessed using Admin > Dashboard > Logging (standard YetaWF site).

    "P": {
      . . .
      "YetaWF_Logging": {
        "NLogMessageFormat": "json",
        "NLogMessageEvent": true,
        "IOMode": "SQL"
        "SQLDbo": "dbo"
        "SQLConnect": "Data Source=....;Initial Catalog=....;User ID=....;Password=...."
      },
.NET Logging

To enable logging using .NET logging the following has to be present in the YetaWF site's AppSettings.json file:

    "P": {
      . . .
      "Logging": {
        . . .
        "Assembly": "YetaWF.LoggingDataProvider",
        "Type": "YetaWF.Modules.LoggingDataProvider.DataProvider.MSLog.LogRecordDataProvider",
        "MinLevel": "0",

This defines the class YetaWF.Modules.LoggingDataProvider.DataProvider.MSLog.LogRecordDataProvider as the logging provider. MinLevel is only used for log records generated by YetaWF.

Configuration settings for .NET logging can be added to the AppSettings.json file. The options available are defined and used by .NET (not YetaWF).

  . . .
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "System": "Information",
      "Microsoft": "Information"
    },
    "Debug": {
      "Default": "Information",
      "System": "Information",
      "Microsoft": "Information"
    },
    "Console": {
      "Default": "Information",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  . . .

The detail level logged is defined using the Application.P.Logging.MinLevel key. Currently 0 defines informational messages, 50 are warnings and >= 99 are errors. For production sites, it is recommended to use the value 50, otherwise too much unnecessary data is logged.

License

The YetaWF.LoggingDataProvider package is part of YetaWF, an open source product licensed under the GNU General Public License, version 3 (GPL-3.0) - Copyright - Softel vdm, Inc.