0
在Google上搜索這個看起來像是永遠的東西之後,我已經在這裏提出了問題。log4net adonetappender變量爲空
我已經爲log4net adonetappender添加了一個自定義字段和變量。然而,重新工作後,嘗試幾乎所有在谷歌的前4頁發現的建議,變量仍然是空的。
任何想法爲什麼發生這種情況和任何建議,以幫助?
輸出
RowId Username DateOfActivity Thread Level Logger Message Exception
16 (null) 2015-08-27 18:53:40.607 124732 DEBUG LogToDatabaseTest.Form1 Retrieving info for ID
App.Config中
<parameter>
<parameterName value="@username"/>
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{username}"/>
</layout>
</parameter>
<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="4000"/>
<layout type="log4net.Layout.ExceptionLayout"/>
</parameter>
C#代碼以設定變量
private void simpleButton1_Click(object sender, EventArgs e)
{
ThreadContext.Properties["username"] = SystemInformation.UserName;
log4net.Config.XmlConfigurator.Configure();//(Watch = false)
try
{
long_ID = Int64.Parse(textEdit1.Text);
}
catch (FormatException fe)
{
XtraMessageBox.Show("ID inputted is not a number! Please enter a valid ID", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
log.Error(String.Format("Retrieving Info for ID: {0}", textEdit1.Text), fe);
return;
}
}