tags:

views:

484

answers:

1

I am using the AdoNetAppender to write to a SQL Server 2005 database table. I have bufferSize set to 1 so that entries are written immediately.

My DBA is concerned that log4net is leaving its database connection open. We have ~50 connections to the database today but only 22 log entries. In several cases there are multiple connections from the same client with different login times.

It sounds to me that connection pooling isn't working or that there's a resource I'm not releasing in code. How should I troubleshoot this?

+1  A: 

SQL Server Profiler will show you all of this. Create a console app, log a few statements, and verify that the connections are opening and closing.

As a side note, I'd recommend not setting your buffer size to 1. For an app of significant size (let's look at NHibernate) it can easily log 100 or more statements for a single operation (depending on the log level). This equates to 100 separate database connections per request and can easily bring a server to its knees.

A buffer size of 5 or 10 will work wonders. Sure you have the risk of losing a few log messages, but in most cases they will eventually be flushed (save power loss or hardware failure).

Ben Scheirman