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

System.ObjectDisposedException with FileAppender+InterProcessLock

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.2.13, 1.2.14, 1.2.15, 1.3.0
    • Fix Version/s: 1.2.14
    • Component/s: Appenders
    • Labels:
      None
    • Flags:
      Patch, Important

      Description

      Configure lockingModel for InterProcessLock with RollingFileAppender.

      app.config
      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
      	<configSections>
      		<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
      	</configSections>
      	<log4net>
      		<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      			<file type="log4net.Util.PatternString" value="test.log" />
      			<encoding value="utf-8" />
      			<appendToFile value="true"/>
      			<rollingStyle value="Size"/>
      			<maxSizeRollBackups value="10"/>
      			<maximumFileSize value="1"/>
      			<staticLogFileName value="true"/>
      			<layout type="log4net.Layout.PatternLayout">
      				<conversionPattern value="%d [%t] %-5p %c{2} - %m%n"/>
      			</layout>
      			<lockingModel type="log4net.Appender.FileAppender+InterProcessLock" />
      		</appender>
      		<root>
      			<level value="INFO"/>
      			<appender-ref ref="RollingFileAppender"/>
      		</root>
      	</log4net>
      </configuration>
      

      Make a log with roll :

      Program.cs
      using log4net;
      
      namespace ConsoleApplication131
      {
      	class Program
      	{
      		static void Main(string[] args)
      		{
      			var log = LogManager.GetLogger(typeof(Program));
      			log.Info("A");
      			log.Info("A");
      		}
      	}
      }
      

      You get this one roll:

      log4net:ERROR Failed to Close appender [RollingFileAppender]
      System.ObjectDisposedException: Safe handle has been closed
         at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext)
         at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext)
         at log4net.Appender.FileAppender.InterProcessLock.AcquireLock()
         at log4net.Appender.FileAppender.LockingStream.AcquireLock()
         at log4net.Appender.FileAppender.WriteFooter()
         at log4net.Appender.TextWriterAppender.WriteFooterAndCloseWriter()
         at log4net.Appender.TextWriterAppender.Reset()
         at log4net.Appender.FileAppender.Reset()
         at log4net.Appender.TextWriterAppender.OnClose()
         at log4net.Appender.AppenderSkeleton.Close()
         at log4net.Util.AppenderAttachedImpl.RemoveAllAppenders()
      

        Activity

        Hide
        _nn_ NN added a comment -

        Patches for trunk and 1.3 branch

        Show
        _nn_ NN added a comment - Patches for trunk and 1.3 branch
        Hide
        nachbarslumpi Dominik Psenner added a comment -

        A modified version of this patch was applied as revision 1711829. Please check if this fixes your situation and feed back the result.

        Show
        nachbarslumpi Dominik Psenner added a comment - A modified version of this patch was applied as revision 1711829. Please check if this fixes your situation and feed back the result.
        Hide
        nachbarslumpi Dominik Psenner added a comment -

        I'm closing the issue for now. If you find that somethings not how it should be, please reopen it.

        Show
        nachbarslumpi Dominik Psenner added a comment - I'm closing the issue for now. If you find that somethings not how it should be, please reopen it.
        Hide
        _nn_ NN added a comment -

        Will you merge these changes to 1.3 branch as well ?
        Thanks

        Show
        _nn_ NN added a comment - Will you merge these changes to 1.3 branch as well ? Thanks

          People

          • Assignee:
            nachbarslumpi Dominik Psenner
            Reporter:
            _nn_ NN
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 1h
              1h
              Remaining:
              Remaining Estimate - 1h
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development