FileLogTraceListener and rolling logs RRS feed

  • Question

  • The logging behavior I am looking for is:

    • create a new file daily
    • when log file exceeds MaxFileSize, create a new file for that day with a new version number

    The first part works fine by setting LogFileCreationSchedule to LogFileCreationScheduleOption.Daily.

    Unfortunately there doesn't seem to be direct support for the 2nd part. The behavior is as described in the documentation:

    "If the log file size (in bytes) is greater than the value of this property, then when the FileLogTraceListener class attempts to write a message to the log, the message is discarded and the failure is either silent or an exception is thrown depending on the value of the DiskSpaceExhaustedBehavior property. Otherwise, the message is written to the log, if the amount of free disk space (in bytes) is less than ReserveDiskSpace."

    I could inherit from FileLogTraceListener, override the Write methods and handle the exception when file size is exceeded to switch to a new file.

    There seems a lot of misinformation about the behavior of FileLogListener out there (http://stackoverflow.com/questions/156575/what-the-best-rollover-log-file-tracelistener-for-net, http://www.questionhub.com/StackOverflow/156575) with people assuming that a new file is used when MaxFileSize is reached. Wondering if I am missing something.


    • Edited by K Suresh Wednesday, July 31, 2013 4:18 PM
    Wednesday, July 31, 2013 4:16 PM