none
Log4net to write multiple files in each and every process when we trigger the events RRS feed

  • Question

  • We have added log4net.config file in our project;
    <log4net>
      <root>
        <level value="ALL" />
        <appender-ref ref="file" />
      </root>
      <appender name="ErrorLog" type="log4net.Appender.RollingFileAppender">
        <file type="log4net.Util.PatternString" value="%property{LogFileName}" />
        <staticLogFileName value="false" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <preserveLogFileNameExtension value="true" />
        <maxSizeRollBackups value="-1" />
        <datePattern value="yyyy-MM-dd_HH-mm-ss'.txt'" />
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%m%n" />
        </layout>
        <filter type="log4net.Filter.PropertyFilter">
          <filter type="log4net.Filter.LevelRangeFilter">
            <levelMin value="DEBUG" />
            <levelMax value="ERROR" />
          </filter>
        </filter>
      </appender>
      <logger name="ErrorLog">
        <maximumFileSize value="15MB" />
        <appender-ref ref="ErrorLog" />
      </logger>
    </log4net>

    we need to log all the messages in every second when we trigger the events but problem is that a new log file created after each and every minute but instead that we need to generate new log file whenever we manually click on a particular button. Any help would be appreciated.
    • Moved by Fei Hu Wednesday, March 7, 2018 7:01 AM Thirdparty product related
    Tuesday, March 6, 2018 7:09 AM

All replies

  • Hi Pooja,

    I do not exactly remember right now as I am currently not on my dev machine. But what I remember we did something like the following write a log when the function and track the function entering and exiting steps.below is the pseudo code. In this way every time get record in log4net when the functions get call., even you can record the function parameter what is passing into the function.

    public string abc(string v1, string v2)
    {
       string.Format("{0} {1}", "Entering Function.", Log.Debug())
    
    //some code
    
       string.Format("{0} {1}", "Exiting Function.", Log.Debug())
    }


    Thanks,
    Sabah Shariq

    [If a post helps to resolve your issue, please click the "Mark as Answer" of that post or click Answered"Vote as helpful" button of that post. By marking a post as Answered or Helpful, you help others find the answer faster. ]


    Tuesday, March 6, 2018 9:38 AM
  • Hello Pooja,

    According to your question is more related to third party product, you could post a new thread to log4net forum for better support.

    If you have some grammar or code errors in using C#, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 7, 2018 7:01 AM