我正在学习NLog,并已转向数据库日志记录。我在网上尝试过多个例子,无法让它们中的任何一个实际插入记录。由于NLog吞噬了它获得的任何异常,我无法理解为什么日志尝试失败。我的记录器和配置没有问题。它执行该行就好像它工作但表保持为空。我在Nlog的例子上迈出了一步,但它也不起作用! :( Nlog Database Example
更新:我最终删除并重新启动配置,它现在可以正常工作。不知道是什么解决了新配置文件的问题,但我也意识到asp渲染导致错误,所以我删除了它们。
<target name="db"
xsi:type="Database"
dbProvider="System.Data.SqlClient"
connectionString="Data Source=Server;Initial Catalog=Database;Persist Security Info=True;Integrated Security=SSPI;"
commandType="StoredProcedure"
commandText="[dbo].[NLog_AddEntry_p]">
<parameter name="@machineName" layout="${machinename}" />
<parameter name="@siteName" layout="${iis-site-name}" />
<parameter name="@logged" layout="${date}" />
<parameter name="@level" layout="${level}" />
<parameter name="@username" layout="${aspnet-user-identity}" />
<parameter name="@message" layout="${message}" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@properties" layout="${all-event-properties:separator=|}" />
<parameter name="@serverName" layout="${aspnet-request:serverVariable=SERVER_NAME}" />
<parameter name="@port" layout="${aspnet-request:serverVariable=SERVER_PORT}" />
<parameter name="@url" layout="${aspnet-request:serverVariable=HTTP_URL}" />
<parameter name="@https" layout="${when:inner=1:when='${aspnet-request:serverVariable=HTTPS}' == 'on'}${when:inner=0:when='${aspnet-request:serverVariable=HTTPS}' != 'on'}" />
<parameter name="@serverAddress" layout="${aspnet-request:serverVariable=LOCAL_ADDR}" />
<parameter name="@remoteAddress" layout="${aspnet-request:serverVariable=REMOTE_ADDR}:${aspnet-request:serverVariable=REMOTE_PORT}" />
<parameter name="@callSite" layout="${callsite}" />
<parameter name="@exception" layout="${exception:tostring}" />
</target>
try
{
int zero = 0;
int result = 100 / zero;
}
catch (Exception ex)
{
Logger filelogger = LogManager.GetLogger("filelogger");
Logger dblogger = LogManager.GetLogger("dblogger");
//filelogger.Error(ex, "Whoops");
dblogger.Error(ex, "Whoops");
}
答案 0 :(得分:0)
问题在于asp布局渲染并缺少它们的包。我还将internalLogging标志设置为无效值。这些更正解决了这个问题。