首页 新闻 会员 周边 捐助

.net使用nlog记录到数据库

0
[待解决问题]

为什么我只能用这种写法记录
LogEventInfo lei = new LogEventInfo();
lei.Level = LogLevel.Error;
lei.Properties["Account"] = "1";
lei.Properties["Date"] =DateTime.Now;
lei.Properties["ActionType"] = "1";
lei.Properties["Level"] = "1";
lei.Properties["Message"] = "1";
logger.Log(lei);
但是简单写法如:logger.Error("12344")虽然记录到了数据库,但是那条数据信息全为空;我的配置文件如下
<target name="database" xsi:type="Database">
<connectionString>${var:ConnectionStrings}</connectionString>
<commandText>
INSERT INTO lifeHome.sys_log (Account,ActionType,Level,Message,Date) Values(@Account,@ActionType,@Level,@Message,@Date)
</commandText>
<parameter name = "@Account" layout = "${event-context:item=Account}"/>
<parameter name = "@ActionType" layout = "${event-context:item=ActionType}"/>
<parameter name = "@Level" layout = "${event-context:item=Level}" />
<parameter name = "@Message" layout = "${event-context:item=Message}" />
<parameter name = "@Date" layout = "${event-context:item=Date}" />
<dbProvider>MySql.Data.MySqlClient.MySqlConnection,Mysql.Data</dbProvider>
</target>
</targets>
<rules>
<logger name="" writeTo="console" />
<logger name="
" minlevel="Debug" writeTo="debugger" />
<logger name="" minlevel="Error" writeTo="error_file" />
<logger name="
" level="Info" writeTo="info" />
<logger name="*" writeTo="database" />
</rules>

灬丶的主页 灬丶 | 初学一级 | 园豆:9
提问于:2018-11-26 23:58
< >
分享
所有回答(1)
0
dudu | 园豆:30939 (高人七级) | 2018-11-27 11:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册