我一直在試圖讓log4net將任何信息或錯誤記錄到我的asp.net web應用程序中的SQL Azure數據庫中,但沒有成功或發生任何明顯的錯誤。我試圖用下面的web.config中使用ADONetAppender附加目的地:log4net AdoNetAppender沒有登錄到Web應用程序中的SQL Azure數據庫
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
/>
</configSections>
<log4net>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data,
Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Server=;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True" />
<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>
<root>
<level value="DEBUG" />
<appender-ref ref="ADONetAppender" />
</root>
</log4net>
....
在我的Global.asax的Application_Start我打電話
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
log4net.Config.XmlConfigurator.Configure();
}
然後嘗試日誌:
readonly ILog _logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
protected void Button1_Click(object sender, EventArgs e)
{
if (_logger.IsInfoEnabled)
_logger.Info("Performance sensitive Info message");
_logger.Info("testing web role into Poqlogging");
_logger.Error("new error",new Exception("new exception"));
}
所有這一切都沒有做,只要我可以tel湖
Windows Azure SQL數據庫(以前稱爲SQL Azure)連接 字符串示例 以下示例顯示SQL數據庫 (以前稱爲SQL Azure)的連接字符串。 <添加名稱= 「的connectionStringName」 的providerName = 「System.Data.SqlClient的」 的connectionString =「數據 源= TCP:ServerName.database.windows.net,1433;初始 目錄=數據庫名;集成安全性= FALSE; User Id = username @ servername; Password = password; Encrypt = True; TrustServerCertificate = False; MultipleActiveResultSets = True「/> // TCP和端口給予麻煩 – Joe