NET Logging Library
Database - SQL Server
Basic Tasks > Database - SQL Server

The SqlServerTarget uses an SQL Server connection string to connect to your SQL Server database.  It works with SQL Server and SQL Server Express.  By default a stored procedure and a log table is automatically created when the first entry is logged.    The default table name is tblLog and the default stored procedure name is spinsert_tbllog.  It automatically discards oldest entries after reaching a default of 10,000 log messages.  This behavior can be overridden.

 

It has these properties that can be configured:

 

tblLog Columns (Automatically Created)
LogID MEDIUMINT NOT NULL AUTO_INCREMENT
LogDate datetime NOT NULL
Message LONGTEXT NOT NULL
Additional LONGTEXT NULL
ElapsedMilliseconds FLOAT NOT NULL
LogLevel varchar(50) NOT NULL
MachineName varchar(100) NOT NULL
UserName varchar(100) NOT NULL
ProcessName varchar(100) NOT NULL
CallingMethod varchar(255) NULL
LineNumber varchar(100) NOT NULL

 

//Example runtime configuration, can also use log.config, app.config, or web.config
Log.ResetConfiguration();

SqlServerTarget target = new SqlServerTarget();
target.ConnectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=test;Integrated Security=SSPI;";
target.TableName = "LogTable";
//Set to zero to not discard max entries
target.MaxEntries = 10000;
Log.Config.Targets.Add(target);

Log.Debug("This is a test");