我使用 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/