I have been attempting to get log4net logging any info or error into my SQL Azure db in my asp.net web application with no success or any noticable errors. I am attempting to use the ADONetAppender appender with the following web.config:

<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>


In my global.asax Application_Start I call

void Application_Start(object sender, EventArgs e) { // Code that runs on application startup log4net.Config.XmlConfigurator.Configure(); }

Then to attempt to log:

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")); }

All of this does nothing as far as I can tell.

Based on the information you provided above several things could go wrong. To better understand the problem more Info needed.

I can provide a few check points which you can verify:

where do you run this application? In compute emulator or on windows Azure IF it is running into Compute Emulator have your setup firewall at SQL Azure to accept connection from your development machine and vice-versa if required. If this application is running in Windows Azure, have you modified the firewall policy Where ever you run this application, you must be able to prove first that a connection to SQL Azure is possible because application itself can not do this, you would have to setup the environment so connection to SQL Azure is working With Log4Net I always do two things: I always verify first that my Log4Net setting/code does work file using the local logging Once above is confirmed, I jump to next step and add code/configuration to change logging to other destination. If all of above are verified, then look for network trace where your application is running (compute Emulator or Windows Azure) for any network data towards SQL Azure server.

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

本文标题:Log4net AdoNetAppender does not connect to sql azure db in a web application

技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(79)