locked
Log4Net in Parallel Context RRS feed

  • Question

  • User-2108369543 posted

    Hi,

    I've a windows service and inside i implemented a task parallel execution. i am using Log4net(AdoNetAppender) to log error+info to database. i want to log all things in each loop(task).After writing log in each loop i need to close the appender of each loop and close the connection of each AdoNetAppender. How can i define appender for each loop and call the close method of each appender. please let me know.

    public class LogHandler
    {
       private ILog _logNet = LogManager.GetLogger(typeof(LogHandler));
    }

    it will probably return the same instance of type ILog, but we need different instance,right?

    var logAppender = _logNet.Logger.Repository.GetAppenders()[0];
    logAppenders.Close();

    How to get the specific appender.and close the connection etc?

    please let me know

      

     

      

    Tuesday, August 23, 2016 12:25 PM

All replies

  • User-2108369543 posted

    Hi Chris Zhao

    i want to log inside a windows service which will run in every 1 hour.In my windows server i am using Parallel.ForEach inside my windows service.i am using AdoNetAppender to log in my sqlserver database.I need to clear my confusion. 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 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?Please let me clear these things. 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?please let me know?it is urgent

    Best Regards

    sabbir

    Monday, August 29, 2016 6:53 PM
  • User-166373564 posted

    Hi Sabbir,

    .i need to close my connection when iteration end and open the connection when iteration start.what to do?please let me know?it is urgent

    From your description above, it seems that this is not a ASP.NET configuration and deployment issue. In this forum, we discuss questions about configuring and deploying ASP.NET applications - web.config, \bin, etc.

    Thanks for your understanding.

    Regards,

    Angie

    Wednesday, August 31, 2016 6:59 AM