mysql - NLog mySQL 数据库作为目标配置

标签 mysql nlog

我使用 Nlog 和 MYsql 作为目标数据库。

我的配置如下:

    <target name="databaselog" type="Database" keepConnection="true" 
       useTransactions="false"
       dbProvider="MySql.Data.MySqlClient"
       connectionString="Server=localhost;Database=****;User ID=****;Password=****;Connect Timeout=5;"
       commandText=" insert into logs(time_stamp,logger,message,log_level) Values(@TIME_STAMP,@LOGGER,@MESSAGE,@LOGLEVEL)">
  <parameter name="@TIME_STAMP" layout="${longdate}"/>
  <parameter name="@LOGGER" layout="${logger}"/>
  <parameter name="@MESSAGE" layout="${message}"/>
  <parameter name="@LOGLEVEL" layout="${level:uppercase=true}"/>
</target>

.

仍然无法在 MYSql DB 中插入信息或任何级别消息。

谁能帮帮我吗?

再见,我也尝试过命令文本为

insert into logs(time_stamp,logger,message,log_level) Values(?,?,?,?)

但无法将数据插入mysql数据库。

最佳答案

来自 NLog docs :

NLog is designed to swallow run-time exceptions that may result from logging. The following settings can change this behavior and/or redirect these messages.

  • <nlog throwExceptions="true" /> - adding the throwExceptions attribute in the config file causes NLog to stop masking exceptions and pass them to the calling application instead. This attribute is useful at deployment time to quickly locate any problems. It’s recommended to set throwExceptions to "false" as soon as the application is properly configured to run, so that any accidental logging problems won’t crash the application.
  • <nlog internalLogFile="file.txt" /> - adding internalLogFile causes NLog to write its internal debugging messages to the specified file. This includes any exceptions that may be thrown during logging.
  • <nlog internalLogLevel="Trace|Debug|Info|Warn|Error|Fatal" /> – determines the internal log level. The higher the level, the less verbose the internal log output.
  • <nlog internalLogToConsole="false|true" /> – determines whether internal logging messages are sent to the console.
  • <nlog internalLogToConsoleError="false|true" /> – determines whether internal logging messages are sent to the console error output (stderr).

关于mysql - NLog mySQL 数据库作为目标配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13022435/

相关文章:

php - 从 in_array 语句获取值

mysql - 如何在 SQL 中合并排序结果中的拖尾字段?

php - UTF-8贯穿始终

visual-studio-2010 - 哪些版本的 NLog 可以与 VS2010 RTM 一起使用?

asp.net-mvc-3 - NLog 在 IIS7 中的 Release模式下失败

mysql - 在两个不同的组中使用 ORDER BY 的 SQL 查询

php - 从需要帮助的表中获取好友详细信息

c# - NLog 的 MongoDb 目标

c# - NLog - 同时抛出异常和日志消息

c# - Autofac 日志记录模块和 ASP.Net Web 表单中的解析参数