Nlog 手动配置

 

var config = new NLog.Config.LoggingConfiguration( );

var logfile = new NLog.Targets.DatabaseTarget( ) { };

logfile.CommandText = "insert into MyLog ([CreateDate], [Origin], [LogLevel], [Message], [StackTrace]) values (@createDate, @origin, @logLevel, @message, @stackTrace);";

logfile.CommandType = System.Data.CommandType.Text;

logfile.ConnectionString = "";

logfile.Name="dblog";

logfile.Parameters.Add( new DatabaseParameterInfo( "@createDate", "${longdate}" ) );

logfile.DBProvider = "MySql.Data.MySqlClient";//System.Data.SqlClient

config.LoggingRules.Add( new NLog.Config.LoggingRule( "*", NLog.LogLevel.Debug, logfile ) );

NLog.LogManager.Configuration = config;
loggerFactory.AddNLog();
posted @ 2020-10-14 17:18  YorkQi  阅读(148)  评论(0编辑  收藏  举报