Point (a) - on the one side, adding IDisposable to ILogWriter is not logically correct. It should define just only logging interface. If there were a class eg. StringLogWriter the IDisposable is meaningless for this class.
On the other side, logging into closeable media (such as file) is the most probable case, so adding IDisposable would be handy.
We will discuss it more internally, however extending an interface is breaking change, so I think the IDisposable is not going to be added into the ILogWriter interface.
I can offer you a workaround using Extension methods:
public static class MyExtensions
{
public static void Close(this ILogWriter logWriter)
{
IDisposable disposable = logWriter as IDisposable;
if (disposable != null)
disposable.Dispose();
}
}
// usage:
client.LogWriter = new FileLogWriter(...);
// do some work ...
client.Disconnect();
client.LogWriter.Close();
Point (b) - closing LogWriter in the NetworkSession.Dispose() method is also not a case, because LogWriter can be shared between NetworkSessions. It is due to ability to log multiple sessions into a single media. If the LogWriter is closed automatically when one NetworkSession is closed, other sessions with shared LogWriter fail to log their state.
But if this is not your case there is also workaround using Dispose pattern:
public class MySftp : Sftp
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
IDisposable disposable = LogWriter as IDisposable;
if (disposable != null)
disposable.Dispose();
}
base.Dispose(disposing);
}
}
// usage:
using (MySftp client = new MySftp())
{
// do some work...
}