Sha256: 0788b5acc11f8bf4a0209cb778085e222e09c9a6b4d93e4d0db57903b683df1c

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

using NLog;
using NLog.Targets;

class Example
{
    static void Main(string[] args)
    {
        DatabaseTarget target = new DatabaseTarget();
        DatabaseParameterInfo param;
        
        target.DBProvider = "mssql";
        target.DBHost = ".";
        target.DBUserName = "nloguser";
        target.DBPassword = "pass";
        target.DBDatabase = "databasename";
        target.CommandText = "insert into LogTable(time_stamp,level,logger,message) values(@time_stamp, @level, @logger, @message);";

        param = new DatabaseParameterInfo();
        param.Name = "@time_stamp";
        param.Layout = "${date}";
        target.Parameters.Add(param);
        
        param = new DatabaseParameterInfo();
        param.Name = "@level";
        param.Layout = "${level}";
        target.Parameters.Add(param);
        
        param = new DatabaseParameterInfo();
        param.Name = "@logger";
        param.Layout = "${logger}";
        target.Parameters.Add(param);
        
        param = new DatabaseParameterInfo();
        param.Name = "@message";
        param.Layout = "${message}";
        target.Parameters.Add(param);

        NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Debug);

        Logger logger = LogManager.GetLogger("Example");
        logger.Debug("log message");
    }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nlog-1.0.0.505.20100822 docs/examples/targets/Configuration API/Database/MSSQL/Example.cs
nlog-1.0.0.505 docs/examples/targets/Configuration API/Database/MSSQL/Example.cs
nlog-1.0.0.505-mswin32 docs/examples/targets/Configuration API/Database/MSSQL/Example.cs