nlog 的手動配置

使用nlog的時候,有時候須要手動配置。好比數據庫連接和密碼不配在文件裏,或者統計配置在一個位置之類的。數據庫

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

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( );
相關文章
相關標籤/搜索