0

I want to log inside a Windows service which will run in every 1 hour. I am using Parallel.ForEach inside my Windows service. I am using AdoNetAppender to log in my sqlserver database.

ILog _log = LogManager.GetLogger(typeof(EmailJob));

The above line means, we are using a static instance to log in database, right? How connection is maintain in AdoNetAppender? When my Windows service complete first iteration and what will be the state of the connection of AdoNetAppender. Is it close at once or waiting for the Garbage collector to dispose? and when next iteration start, will it open a new connection?

As my Windows service is running always, if Garbage collector take long time to dispose the object, number of open connections will cross the limit of max open connections of SQL Server. I need to close my connection when iteration end and open the connection when iteration start. What to do?

halfer
  • 19,824
  • 17
  • 99
  • 186
user3352074
  • 145
  • 3
  • 14
  • A good tip for posting here is that whilst it may be urgent for you, it is not urgent for anyone else. Please read [this community discussion](http://meta.stackoverflow.com/q/326569/472495). – halfer Aug 30 '16 at 07:59

1 Answers1

1

The line of code in your sample is not a static log variable, you are wondering how the GC will collect your variable. It does only when there are no more references to the object. Besides that you make a lot of assumptions on the internal working of the AdoNetAppender. Your connection is idd maintained in the AdoNetAppender, however it uses a buffer and only writes when the buffer is full. The connection management is done by driver you are referencing in you connection string, you should not worry about if it is open or closed. Normally you should only worry about this when you have a concrete problem caused by the logger. So what symptoms do you see that point to the logger is causing you any problems?

Peter
  • 27,590
  • 8
  • 64
  • 84