I'm using log4net appender ADO.NET to log messages of Azure Worker Role to the SQL Azure instance (default diagnostics just does not fit). For some reason, while running the worker in dev fabric, logging works. Yet, when the instance is deployed to the cloud (with exactly the same config) errors do not get logged.
Configuration happens in the code using this file:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<renderer renderingClass="{ExceptionRenderer}" renderedClass="System.Exception" />
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<layout type="log4net.Layout.PatternLayout">
<!--<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />-->
<conversionPattern value="%message%newline" />
</layout>
</appender>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="3" />
<connectionType value="{ConnectionType}" />
<connectionString value="{ConnectionString}" />
<commandText value="INSERT INTO Salescast_Log ([Date],[Thread],[Version],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, '{Version}',@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="4000" />
<layout type="{ExceptionLayoutType}" />
</parameter>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="ERROR" />
<levelMax value="FATAL" />
</filter>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="TraceAppender" />
<appender-ref ref="AdoNetAppender" />
</root>
</log4net>
log4net is initialized with the proper values, when the Autofac IoC environment is initalized (per role startup). The code looks like this:
static ILogProvider BuildProvider(IComponentContext context)
{
var connection = context
.Resolve<IProvideBusSettings>()
.GetString("SqlConnection")
.ExposeException("Failed to get SQL string for logging");
var xml = Properties.Resources.Logging
.Replace("{ConnectionType}", typeof(SqlConnection).AssemblyQualifiedName)
.Replace("{ConnectionString}", connection)
.Replace("{ExceptionLayoutType}", typeof(LoggingTrimmedExceptionLayout).AssemblyQualifiedName)
.Replace("{ExceptionRenderer}", typeof(LoggingExceptionRenderer).AssemblyQualifiedName)
.Replace("{Version}", SystemDescriptor.Default.Version.ToString());
var doc = new XmlDocument();
doc.LoadXml(xml);
XmlConfigurator.Configure(doc.DocumentElement);
return new LoggingProvider();
}
Default Azure OS is used. SQL connections are obviously valid.
Could anybody, please, think of reason, why log4net logs errors from the dev fabric, but fails to do that from the azure OS, using exactly the same service configuration files?