NLog配置文件:

<target xsi:type="Database" name="database" connectionString="Data Source=10.1.11.139;Initial Catalog=EnterpriseOPDB;User Id=sa;Password=Asdf1234">
<commandText>
insert into [EnterpriseTest].[dbo].MyLog ([CreateDate], [Origin], [LogLevel], [Message], [StackTrace]) values (@createDate, @origin, @logLevel, @message, @stackTrace);
</commandText>
<parameter name="@createDate" layout="${longdate}"/>
<!--日志发生时间-->
<parameter name="@origin" layout="${callsite}"/>
<!--日志来源-->
<parameter name="@logLevel" layout="${level}"/>
<!--日志等级-->
<parameter name="@message" layout="${message}"/>
<!--日志信息-->
<parameter name="@stackTrace" layout="${stacktrace}"/>
<!--堆栈信息-->
</target>
<logger name="DefaultLog" minlevel="Debug" writeTo="database" />
05-04 12:50