Database target
If you want to contribute, please create a user account and contact Jarek to get edit access.
Writes log messages to the database using an ADO.NET provider.
Supported in


Configuration Syntax
<targets>
<target xsi:type="Database"
name="String"
dbUserName="Layout"
dbProvider="String"
useTransactions="Boolean"
connectionStringName="String"
connectionString="Layout"
keepConnection="Boolean"
dbDatabase="Layout"
dbPassword="Layout"
dbHost="Layout"
installConnectionString="Layout"
commandText="Layout">
<install-command commandType="Enum" connectionString="Layout" ignoreFailures="Boolean"
text="Layout"/><!-- repeated -->
<uninstall-command commandType="Enum" connectionString="Layout" ignoreFailures="Boolean"
text="Layout"/><!-- repeated -->
<parameter layout="Layout" name="String" precision="Byte"
scale="Byte" size="Integer"/><!-- repeated -->
</target>
</targets>
Read more about using the Configuration File.<target xsi:type="Database"
name="String"
dbUserName="Layout"
dbProvider="String"
useTransactions="Boolean"
connectionStringName="String"
connectionString="Layout"
keepConnection="Boolean"
dbDatabase="Layout"
dbPassword="Layout"
dbHost="Layout"
installConnectionString="Layout"
commandText="Layout">
<install-command commandType="Enum" connectionString="Layout" ignoreFailures="Boolean"
text="Layout"/><!-- repeated -->
<uninstall-command commandType="Enum" connectionString="Layout" ignoreFailures="Boolean"
text="Layout"/><!-- repeated -->
<parameter layout="Layout" name="String" precision="Byte"
scale="Byte" size="Integer"/><!-- repeated -->
</target>
</targets>
Parameters
- General Options
- name - Name of the target.
- Connection Options
- dbUserName - Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string.Layout
- dbProvider - Name of the database provider. Required. Default: sqlserverThe parameter name should be a provider invariant name as registered in machine.config or app.config. Common values are:
System.Data.SqlClient -System.Data.SqlServerCe.3.5 -System.Data.OracleClient - (deprecated in .NET Framework 4)Oracle.DataAccess.Client -System.Data.SQLite -Npgsql -MySql.Data.MySqlClient -
sqlserver ,mssql ,microsoft ormsde - SQL Server Data Provideroledb - OLEDB Data Providerodbc - ODBC Data Provider
- useTransactions - Indicates whether to use database transactions. Some data providers require this.Boolean Default: False
- connectionStringName - Name of the connection string (as specified in .

This parameter is not supported in:
- NLog v1.0 for .NET Compact Framework 1.0
- NLog v1.0 for .NET Compact Framework 2.0
- NLog v1.0 for .NET Framework 1.0
- NLog v1.0 for .NET Framework 1.1
- NLog v1.0 for .NET Framework 2.0
- NLog v2.0 for .NET Compact Framework 2.0
- NLog v2.0 for .NET Compact Framework 3.5
- connectionString - Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase.Layout
- keepConnection - Indicates whether to keep the database connection open between the log events.Boolean Default: True
- dbDatabase - Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string.Layout
- dbPassword - Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string.Layout
- dbHost - Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string.Layout
- Installation Options
- installDdlCommands - The installation DDL commands.Collection

Each collection item is represented by<install-command />element with the following attributes:- commandType - Type of the command. Required. Default: 1

Possible values: - connectionString - Connection string to run the command against. If not provided, connection string from the target is used.Layout

- ignoreFailures - Indicates whether to ignore failures.Boolean

- parameters - The collection of parameters. Each parameter contains a mapping between NLog layout and a database named or positional parameter.Collection

Each collection item is represented by<parameter />element with the following attributes: - text - Command text.Layout Required.

This parameter is not supported in:
- NLog v1.0 for .NET Compact Framework 1.0
- NLog v1.0 for .NET Compact Framework 2.0
- NLog v1.0 for .NET Framework 1.0
- NLog v1.0 for .NET Framework 1.1
- NLog v1.0 for .NET Framework 2.0
- installConnectionString - Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used.Layout

This parameter is not supported in:
- NLog v1.0 for .NET Compact Framework 1.0
- NLog v1.0 for .NET Compact Framework 2.0
- NLog v1.0 for .NET Framework 1.0
- NLog v1.0 for .NET Framework 1.1
- NLog v1.0 for .NET Framework 2.0
- uninstallDdlCommands - The uninstallation DDL commands.Collection

Each collection item is represented by<uninstall-command />element with the following attributes:- commandType - Type of the command. Required. Default: 1

Possible values: - connectionString - Connection string to run the command against. If not provided, connection string from the target is used.Layout

- ignoreFailures - Indicates whether to ignore failures.Boolean

- parameters - The collection of parameters. Each parameter contains a mapping between NLog layout and a database named or positional parameter.Collection

Each collection item is represented by<parameter />element with the following attributes: - text - Command text.Layout Required.

This parameter is not supported in:
- NLog v1.0 for .NET Compact Framework 1.0
- NLog v1.0 for .NET Compact Framework 2.0
- NLog v1.0 for .NET Framework 1.0
- NLog v1.0 for .NET Framework 1.1
- NLog v1.0 for .NET Framework 2.0
- SQL Statement
- commandText - Text of the SQL command to be run on each log level.Layout Required.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. - parameters - The collection of parameters. Each parameter contains a mapping between NLog layout and a database named or positional parameter.Collection
Each collection item is represented by<parameter />element with the following attributes:




