Class FileAppender.LockingModelBase
Locking model base class
public abstract class FileAppender.LockingModelBase
- Inheritance
-
FileAppender.LockingModelBase
- Derived
- Inherited Members
Remarks
Base class for the locking models available to the FileAppender derived loggers.
Constructors
LockingModelBase()
protected LockingModelBase()
Properties
CurrentAppender
Gets or sets the FileAppender for this LockingModel
public FileAppender CurrentAppender { get; set; }
Property Value
- FileAppender
The FileAppender for this LockingModel
Remarks
The file appender this locking model is attached to and working on behalf of.
The file appender is used to locate the security context and the error handler to use.
The value of this property will be set before OpenFile(string, bool, Encoding) is called.
Methods
AcquireLock()
Acquire the lock on the file
public abstract Stream AcquireLock()
Returns
- Stream
A stream that is ready to be written to.
Remarks
Acquire the lock on the file in preparation for writing to it. Return a stream pointing to the file. ReleaseLock() must be called to release the lock on the output file.
ActivateOptions()
Initializes all resources used by this locking model.
public abstract void ActivateOptions()
CloseFile()
Close the file
public abstract void CloseFile()
Remarks
Close the file. No further writes will be made.
CloseStream(Stream)
Helper method to close stream under CurrentAppender's SecurityContext.
protected void CloseStream(Stream stream)
Parameters
streamStream
Remarks
Does not set stream to null.
CreateStream(string, bool, FileShare)
Helper method that creates a FileStream under CurrentAppender's SecurityContext.
protected Stream CreateStream(string filename, bool append, FileShare fileShare)
Parameters
Returns
Remarks
Typically called during OpenFile or AcquireLock.
If the directory portion of the filename does not exist, it is created
via Directory.CreateDirecctory.
OnClose()
Disposes all resources that were initialized by this locking model.
public abstract void OnClose()
OpenFile(string, bool, Encoding)
Open the output file
public abstract void OpenFile(string filename, bool append, Encoding encoding)
Parameters
filenamestringThe filename to use
appendboolWhether to append to the file, or overwrite
encodingEncodingThe encoding to use
Remarks
Open the file specified and prepare for logging. No writes will be made until AcquireLock() is called. Must be called before any calls to AcquireLock(), ReleaseLock() and CloseFile().
ReleaseLock()
Release the lock on the file
public abstract void ReleaseLock()
Remarks
Release the lock on the file. No further writes will be made to the stream until AcquireLock() is called again.