In the existing project we have log4net configured to use custom ADO.NET Appender (AsglAppender) to write errors to SQL Server database:
public class AsglAppender : BufferingAppenderSkeleton
And log4net config section is defined like this:
<log4net>
<appender name="AsglAppender" type="Asgl.Core.Logging.AsglAppender, Asgl.Core" />
<appender name="TcpAppender" type="Asgl.Logging.TcpAppender, Asgl">
<param name="LocalPort" value="882" />
<layout type="log4net.Layout.XmlLayout" />
</appender>
<logger name="NHibernate">
<level value="OFF" />
</logger>
<root>
<level value="ERROR" />
<appender-ref ref="AsglAppender" />
</root>
<!--
<root>
<level value="ALL" />
<appender-ref ref="TcpAppender" />
</root>
-->
</log4net>
When logger.Error("Some error message"); is called I get this exception thrown:
System.Data.SqlClient.SqlException (0x80131904): INSERT failed because the following SET options have incorrect settings: 'ANSI_NULLS'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.
This is an existing code that supposingly was working fine before.
After debugging I found out that this overridden method of AsglAppender is being called
protected override void SendBuffer(LoggingEvent[] events)
which executed a custom ErrorInsert stored procedure that does the job of inserting the error message into the table. I checked the stored procedure and found out it was created with SET ANSI_NULLS OFF
After I changed it to SET ANSI_NULLS ON, the logging started to work no problem. Not sure why this setting affects the logging this way...
User contributions licensed under CC BY-SA 3.0