Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-634

Attempting to flush a FileAppender throws LockStateException

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.8
    • Fix Version/s: None
    • Component/s: Appenders
    • Labels:

      Description

      I'd like to be able to have file appenders which do not immediately flush, but instead flush on command.

       

      The documentation for log4net, as well as the api interface appears to communicate that this is possible.

       

      However, when I actually try to do this (after configuring ImmediateFlush to false), I get the following exception:

      log4net.Appender.FileAppender+LockingStream+LockStateException: The file is not currently locked

       

      Which is surprising, because, yes, of course the file isn't locked – nothing is writing to it.

       

      Whilst spelunking the code to figure out what I could possibly be doing wrong, I also stumbled across some logic which I find confusing, and would love to have cleared up:

       

      1. XmlConfigurator, on .net standard, cannot configure for all repositories – it must accept a repository, where .net framework variants do not need this. Why? How do I configure my entire application from .net core then?
      2. the Flush method on a FileAppender takes a timeout value – which is never used. Why?
      3. the Flush method on LogManager behaves very differently from netstandard than from net framework – the latter attempts to flush for the repository associated with the calling assembly where the former simply returns false. Why?

       

      All-in-all, I thought that I had a simple requirement to be able to flush a logfile to disk, but it turns out to have been an adventure in confusion on my part.
       

        Attachments

        1. TestProject1.zip
          9 kB
          Davyd McColl

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              davydm Davyd McColl
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: