Search code examples
azurelog4netlog4net-configuration

How can I debug log4net not writing on an Azure App Service


I just pushed up a new version of my app service to Azure. It's running ok, but returning an error on my REST calls.

The problem is log4net is not writing to the logging database. And that gives me the question - how do I see what's going wrong when logging isn't working (it was previously but appears to have stopped working 11 October 2018.

What I have for the config is:

 <log4net>
    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="Server=tcp:*****,1433;Database=Log4Net;User ID=***@***p;Password=*****;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" />
      <commandText value="INSERT INTO UpdateLog ([Date],[Level],[Message],[Exception],[RemoteHost],[Cookie],[Url],[QueryString],[Referrer],[RequestMethod],[ScriptPath],[UserAgent],[Domain],[CustomBlob]) VALUES                     (@log_date, @log_level, @message, @exception,@remote_host,@cookie,@url,@query_string,@referrer,@request_method,@script_path,@user_agent,@domain,@custom_blob)" />
      <parameter>
        <parameterName value="@log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
...

Solution

  • Kudo is my favourite tool for this kind of investigation. By using Kudo you can open AppService VM and you can see all type of logs (Application and IIS).

    You can also Check log4net internal logs by enabling debug mode

    <configuration>
    <appSettings>
      <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>
    </configuration>