我正在尝试使用NLog配置数据库。以下是NLog.config文件中的完整代码:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true"
internalLogLevel="Trace"
internalLogFile="..\..\..\Logs\nlog-app.log">
<targets>
<!-- file targets -->
<target name="asyncFile" xsi:type="AsyncWrapper">
<target xsi:type="File" name="f" fileName="${basedir}/Log/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message} ${aspnet-user-identity}"/>
</target>
<!-- database targets -->
<target name="database" xsi:type="Database" keepConnection="true" useTransactions="true"
dbProvider="System.Data.SqlClient"
connectionString="Data Source=.;Initial Catalog=Test;Integrated Security=SSPI"
commandText="insert into MyLog(CreateDate,LogLevel,log_logger,Message) values(@time_stamp, @level, @logger, @message)">
<parameter name="@time_stamp" layout="${date}" />
<parameter name="@level" layout="${level}" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@message" layout="${message}" />
</target>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Debug" writeTo="asyncFile,database" />
</rules>
</nlog>
表格结构:
CREATE TABLE MyLog
(
[CreateDate] [datetime] NULL,
[Origin] [varchar](200) NULL,
[LogLevel] [varchar](100) NULL,
[log_logger] [varchar](8000) NULL,
[Message] [varchar](8000) NULL,
[Exception] [varchar](8000) NULL,
[StackTrace] [varchar](8000) NULL,
)
由于配置文件中给出了配置,因此无法找出错误。所以请通过可能的解决方案告诉我这个问题。