我有以下控制台应用程序,该应用程序使用程序化配置使用NLog来实现日志记录。当前,它当前未登录到数据库,并且在运行数据库时不会引发任何异常。有人可以让我知道其背后的原因吗?
using NLog;
using NLog.Config;
using NLog.Targets;
using System;
namespace Test.Logger
{
class Program
{
static void Main(string[] args)
{
var logConfig = new LoggingConfiguration();
//dbtarget 2
var dbTarget2 = new DatabaseTarget();
dbTarget2.ConnectionString = "SomeConnectionString";
dbTarget2.CommandText = @"INSERT INTO [dbo].[LogAppDetail]
([LogAppIS]
,[LogAppId]
,[DN]
,[DV])
VALUES
(@LogAppIS
,@LogAppId
,@DN
,@DV)";
dbTarget2.Parameters.Add(new DatabaseParameterInfo("@LogAppIS", new NLog.Layouts.SimpleLayout("${event-properties:LogAppIS}")));
dbTarget2.Parameters.Add(new DatabaseParameterInfo("@LogAppId", new NLog.Layouts.SimpleLayout("${event-properties:LogAppId}")));
dbTarget2.Parameters.Add(new DatabaseParameterInfo("@DN", new NLog.Layouts.SimpleLayout("${event-properties:DN}")));
dbTarget2.Parameters.Add(new DatabaseParameterInfo("@DV", new NLog.Layouts.SimpleLayout("${event-properties:DV}")));
logConfig.AddTarget("dbTarget2", dbTarget2);
// add rules
var rule2 = new LoggingRule("LogAppDetail", LogLevel.Trace, dbTarget2);
logConfig.LoggingRules.Add(rule2);
LogManager.Configuration = logConfig;
}
}
}
慕婉清6462132
相关分类