0
我試圖使用log4net在兩個不同的表中創建日誌。第一個adonetappender會登錄到一個名爲'log'的表中,並且應該是標準的id,日期,線程,級別等等。第二個adonetappender需要記錄到一個名爲'usageLog'的三個表中,並且只需要記錄日期/時間和兩個額外的字符串值。我不能爲我的生活弄清楚。我需要做什麼?下面是我的配置到目前爲止。我不確定它是否正確,我不知道如何在程序中使用它。log4net多個adonetappender每個都有自定義字段
<log4net>
<logger additivity="false" name="Log">
<level value="INFO"/>
<appender-ref ref="LogAppender" />
</logger>
<logger additivity="false" name="UsageLog">
<level value="INFO"/>
<appender-ref ref="UsageLogAppender" />
</logger>
<appender name="LogAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<!-- Causes errors to be written immediately - default is 100 -->
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=dummy;initial catalog=dummy;integrated security=false;persist security info=True;User ID=dummy;Password=dummy" />
<commandText value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@thread" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
<parameter>
<parameterName value="@logger" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger" />
</layout>
</parameter>
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@exception" />
<dbType value="String" />
<size value="2000" />
<layout type="log4net.Layout.ExceptionLayout" />
</parameter>
</appender>
<appender name="UsageLogAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<!-- Causes errors to be written immediately - default is 100 -->
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=dummy;initial catalog=dummy;integrated security=false;persist security info=True;User ID=dummy;Password=dummy" />
<commandText value="INSERT INTO UsageLog ([Date],[ManDesc],[ModDesc]) VALUES (@log_date, @man_desc, @model_desc)" />
<parameter>
<parameterName value="@log_date" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@man_desc" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.RawPropertyLayout">
<conversionPattern value="%property{man_desc}" />
</layout>
</parameter>
<parameter>
<parameterName value="@model_desc" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{model_desc}" />
</layout>
</parameter>
</appender>
這是一個有點很難看出有什麼不對,你可以檢查以下內容:做日誌的工作,當你寫在磁盤上的文本文件?如果不是,請再次查看log4net的配置步驟以查看可能存在的問題。如果有,請檢查憑據是否正確,並且如果命令行調用到您的sql數據庫,則應用程序將部署到該機器。 – samy 2014-09-11 09:24:07