NLog.Database
Information about database command + parameters.
Gets or sets the type of the command.
The type of the command.
Gets or sets the connection string to run the command against. If not provided, connection string from the target is used.
Gets or sets the command text.
Gets or sets a value indicating whether to ignore failures.
Gets the collection of parameters. Each parameter contains a mapping
between NLog layout and a database named or positional parameter.
Information about object-property for the database-connection-object
Initializes a new instance of the class.
Gets or sets the name for the object-property
Gets or sets the value to assign on the object-property
Gets or sets the type of the object-property
Gets or sets convert format of the property value
Gets or sets the culture used for parsing property string-value for type-conversion
Render Result Value
Log event for rendering
Result value when available, else fallback to defaultValue
Represents a parameter to a Database target.
Initializes a new instance of the class.
Initializes a new instance of the class.
Name of the parameter.
The parameter layout.
Gets or sets the database parameter name.
Gets or sets the layout that should be use to calculate the value for the parameter.
Gets or sets the database parameter DbType.
Gets or sets the database parameter size.
Gets or sets the database parameter precision.
Gets or sets the database parameter scale.
Gets or sets the type of the parameter.
Gets or sets the fallback value when result value is not available
Gets or sets convert format of the database parameter value.
Gets or sets the culture used for parsing parameter string-value for type-conversion
Gets or sets whether empty value should translate into DbNull. Requires database column to allow NULL values.
Render Result Value
Log event for rendering
Result value when available, else fallback to defaultValue
Writes log messages to the database using an ADO.NET provider.
Note .NET Core application cannot load connectionstrings from app.config / web.config. Instead use ${configsetting}
See NLog Wiki
Documentation on NLog Wiki
The configuration is dependent on the database type, because
there are different methods of specifying connection string, SQL
command and command parameters.
MS SQL Server using System.Data.SqlClient:
Oracle using System.Data.OracleClient:
Oracle using System.Data.OleDBClient:
To set up the log target programmatically use code like this (an equivalent of MSSQL configuration):
Initializes a new instance of the class.
Initializes a new instance of the class.
Name of the target.
Gets or sets the name of the database provider.
The parameter name should be a provider invariant name as registered in machine.config or app.config. Common values are:
- System.Data.SqlClient - SQL Sever Client
- System.Data.SqlServerCe.3.5 - SQL Sever Compact 3.5
- System.Data.OracleClient - Oracle Client from Microsoft (deprecated in .NET Framework 4)
- Oracle.DataAccess.Client - ODP.NET provider from Oracle
- System.Data.SQLite - System.Data.SQLite driver for SQLite
- Npgsql - Npgsql driver for PostgreSQL
- MySql.Data.MySqlClient - MySQL Connector/Net
(Note that provider invariant names are not supported on .NET Compact Framework).
Alternatively the parameter value can be be a fully qualified name of the provider
connection type (class implementing ) or one of the following tokens:
- sqlserver, mssql, microsoft or msde - SQL Server Data Provider
- oledb - OLEDB Data Provider
- odbc - ODBC Data Provider
Gets or sets the name of the connection string (as specified in <connectionStrings> configuration section.
Gets or sets the connection string. When provided, it overrides the values
specified in DBHost, DBUserName, DBPassword, DBDatabase.
Gets or sets the connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used.
Gets the installation DDL commands.
Gets the uninstallation DDL commands.
Gets or sets a value indicating whether to keep the
database connection open between the log events.
Gets or sets the database host name. If the ConnectionString is not provided
this value will be used to construct the "Server=" part of the
connection string.
Gets or sets the database user name. If the ConnectionString is not provided
this value will be used to construct the "User ID=" part of the
connection string.
Gets or sets the database password. If the ConnectionString is not provided
this value will be used to construct the "Password=" part of the
connection string.
Gets or sets the database name. If the ConnectionString is not provided
this value will be used to construct the "Database=" part of the
connection string.
Gets or sets the text of the SQL command to be run on each log level.
Typically this is a SQL INSERT statement or a stored procedure call.
It should use the database-specific parameters (marked as @parameter
for SQL server or :parameter for Oracle, other data providers
have their own notation) and not the layout renderers,
because the latter is prone to SQL injection attacks.
The layout renderers should be specified as <parameter /> elements instead.
Gets or sets the type of the SQL command to be run on each log level.
This specifies how the command text is interpreted, as "Text" (default) or as "StoredProcedure".
When using the value StoredProcedure, the commandText-property would
normally be the name of the stored procedure. TableDirect method is not supported in this context.
Gets the collection of parameters. Each item contains a mapping
between NLog layout and a database named or positional parameter.
Gets the collection of properties. Each item contains a mapping
between NLog layout and a property on the DbConnection instance
Gets the collection of properties. Each item contains a mapping
between NLog layout and a property on the DbCommand instance
Configures isolated transaction batch writing. If supported by the database, then it will improve insert performance.
Performs installation which requires administrative permissions.
The installation context.
Performs uninstallation which requires administrative permissions.
The installation context.
Determines whether the item is installed.
The installation context.
Value indicating whether the item is installed or null if it is not possible to determine.
Set the to use it for opening connections to the database.
Writes the specified logging event to the database. It creates
a new database command, prepares parameters for it by calculating
layouts and executes the command.
The logging event.
Writes an array of logging events to the log target. By default it iterates on all
events and passes them to "Write" method. Inheriting classes can use this method to
optimize batch writes.
Logging events to be written out.
Write logEvent to database
Build the connectionstring from the properties.
Using at first, and falls back to the properties ,
, and
Event to render the layout inside the properties.
Escape quotes and semicolons.
See https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms722656(v=vs.85)#setting-values-that-use-reserved-characters
Create database parameter
Current command.
Parameter configuration info.
Extract parameter value from the logevent
Current logevent.
Parameter configuration info.
Reflection helpers.