We're using log4net 1.2.11 to log to a SQL Server database from an internal
Windows service. For the most part, log4net is working very well except for
when SQL Server terminates the inactive log4net connection overnight.
I have the "reconnectonerror" property set to "true" in the log4net.config file
but the database connection doesn't appear to get re-established.
Anyway, I found how to enable log4net internal debugging and when I enable it,
I get log messages but nothing from the AdoNetAppender. I can see the
AdoNetAppender being setup, but when I successfully log to the database using
the AdoNetAppender, I get nothing in the debug output. I also use a
RollingFileAppender to log messages generated by our Windows service and I can
see debug messages showing the log file getting rolled, per our
RollingFileAppender configuration settings.
So, my questions are:
1) How can I get internal debug output from the AdoNetAppender?
2) What is the best way to debug failed attempts to reconnect to the SQL
Server database?
We're connecting to SQL Server 2008 and when things do work, log messages get
logged in the database as desired.
Here is a snipet from our app.config file, which enables internal log4net
debugging:
-------------- START -----------------
<appSettings>
.....
<add key="log4net.Internal.Debug" value="true" />
</appSettings>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="log4net-debug.log" />
</listeners>
</trace>
</system.diagnostics>
-------------- END --------------------
That creates a "log4net-debug.log" file that contains lots of info, once the
Windows service has been running for a while.
Here is a snipet from our log4net.config file, which defines our appenders:
-------------- START ------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="service.log" />
<appendToFile value="true" />
<maximumFileSize value="100kb" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %a %logger =
%message%newline" />
</layout>
</appender>
<appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken={some string}" />
<connectionString value="{connection string for database connection}" />
<commandText value="{SQL INSERT statement to log data}" />
<reconnectonerror value="true" />
<parameter>
<parameterName value="@application" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%appdomain" />
</layout>
</parameter>
(more parameters are defined similar to the above parameter)
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</root>
<logger name="DBLog">
<appender-ref ref="ADONetAppender" />
</logger>
</log4net>
</configuration>
--------------- END --------------------
So, with the above settings, when I first start the Windows service, the
log4net-debug.log file shows the creation of the appenders and it will
eventually show the rolling of the log file. I never see any messages from the
ADONetAppender showing it logging messages to the database.
Thanks!
Tom
-----------------------------------------
The information contained in this electronic mail message is
confidential information intended only for the use of the
individual or entity named above. The information herein may also
be protected by the Electronic Communications Privacy Act, 18 USC
Sections 2510-2521. If the reader of this message is not the
intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly
prohibited. If you have received this communication in error,
please immediately notify us by e-mail and delete the original
message. In addition, to ensure compliance with requirements
imposed by the IRS, we inform you that any U.S. tax advice
contained in this communication (including any attachments) is not
intended or written to be used, and cannot be used, for the purpose
of (a) avoiding penalties under the Internal Revenue Code, or (b)
promoting, marketing or recommending to another party any matters
addressed in this communication. Thank you.