FileAppender Class | Apache log4net™ SDK Documentation

Appends logging events to a file.
Inheritance Hierarchy

System
Object
log4net.Appender
AppenderSkeleton
log4net.Appender
TextWriterAppender
log4net.Appender
FileAppender
log4net.Appender
RollingFileAppender

Namespace: log4net.Appender
Assembly: log4net (in log4net.dll) Version: 2.0.8.0-.NET 4.0
Syntax

C#
VB
C++
F#
Copy

    public class FileAppender : TextWriterAppender

    Public Class FileAppender
    	Inherits TextWriterAppender

    public ref class FileAppender : public TextWriterAppender

    type FileAppender =
        class
            inherit TextWriterAppender
        end

The FileAppender type exposes the following members.

Constructors

| Name | Description
--- | --- | ---
| FileAppender | Default constructor
| FileAppender(ILayout, String) | Obsolete. Construct a new appender using the layout and file specified. The file will be appended to.
| FileAppender(ILayout, String, Boolean) | Obsolete. Construct a new appender using the layout, file and append mode.

Top
Properties

| Name | Description
--- | --- | ---
| AppendToFile | Gets or sets a flag that indicates whether the file should be appended to or overwritten.
| Encoding | Gets or sets Encoding used to write to the file.
| ErrorHandler | Gets or set the IErrorHandler and the underlying QuietTextWriter, if any, for this appender. (Inherited from TextWriterAppender.)
| File | Gets or sets the path to the file that logging will be written to.
| FilterHead | The filter chain. (Inherited from AppenderSkeleton.)
| ImmediateFlush | Gets or set whether the appender will flush at the end of each append operation. (Inherited from TextWriterAppender.)
| Layout | Gets or sets the ILayout for this appender. (Inherited from AppenderSkeleton.)
| LockingModel | Gets or sets the LockingModel used to handle locking of the file.
| Name | Gets or sets the name of this appender. (Inherited from AppenderSkeleton.)
| QuietWriter | Gets or sets the QuietTextWriter where logging events will be written to. (Inherited from TextWriterAppender.)
| RequiresLayout | This appender requires a log4net.Layout to be set. (Inherited from TextWriterAppender.)
| SecurityContext | Gets or sets the SecurityContext used to write to the file.
| Threshold | Gets or sets the threshold Level of this appender. (Inherited from AppenderSkeleton.)
| Writer | Sets the TextWriter where the log output will go. (Inherited from TextWriterAppender.)

Top
Methods

| Name | Description
--- | --- | ---
| ActivateOptions | Activate the options on the file appender. (Overrides AppenderSkeleton ActivateOptions .)
| AddFilter | Adds a filter to the end of the filter chain. (Inherited from AppenderSkeleton.)
| Append(LoggingEvent) | This method is called by the DoAppend(LoggingEvent) method. (Overrides TextWriterAppender Append(LoggingEvent).)
| Append( LoggingEvent ) | This method is called by the DoAppend( LoggingEvent ) method. (Overrides TextWriterAppender Append( LoggingEvent ).)
| ClearFilters | Clears the filter list for this appender. (Inherited from AppenderSkeleton.)
| Close | Closes the appender and release resources. (Inherited from AppenderSkeleton.)
| CloseFile | Closes the previously opened file.
| CloseWriter | Closes the underlying TextWriter. (Overrides TextWriterAppender CloseWriter .)
| ConvertToFullPath | Convert a path into a fully qualified path.
| DoAppend(LoggingEvent) | Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent)] method. (Inherited from AppenderSkeleton.)
| DoAppend( LoggingEvent ) | Performs threshold checks and invokes filters before delegating actual logging to the subclasses specific [M:Append(LoggingEvent[])] method. (Inherited from AppenderSkeleton.)
| Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
| FilterEvent | Test if the logging event should we output by this appender (Inherited from AppenderSkeleton.)
| Finalize | Finalizes this appender by calling the implementation's Close method. (Inherited from AppenderSkeleton.)
| Flush | Flushes any buffered log data. (Inherited from TextWriterAppender.)
| GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.)
| GetType | Gets the Type of the current instance. (Inherited from Object.)
| IsAsSevereAsThreshold | Checks if the message level is below this appender's threshold. (Inherited from AppenderSkeleton.)
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.)
| OnClose | Close this appender instance. The underlying stream or writer is also closed. (Overrides TextWriterAppender OnClose .)
| OpenFile | Sets and opens the file where the log output will go. The specified file must be writable.
| PreAppendCheck | This method determines if there is a sense in attempting to append. (Inherited from TextWriterAppender.)
| PrepareWriter | Called to initialize the file writer (Overrides TextWriterAppender PrepareWriter .)
| RenderLoggingEvent(LoggingEvent) | Renders the LoggingEvent to a string. (Inherited from AppenderSkeleton.)
| RenderLoggingEvent(TextWriter, LoggingEvent) | Renders the LoggingEvent to a string. (Inherited from AppenderSkeleton.)
| Reset | Closes any previously opened file and calls the parent's Reset . (Overrides TextWriterAppender Reset .)
| SafeOpenFile | Sets and opens the file where the log output will go. The specified file must be writable.
| SetQWForFiles(Stream) | Sets the quiet writer used for file output
| SetQWForFiles(TextWriter) | Sets the quiet writer being used.
| ToString | Returns a String that represents the current Object. (Inherited from Object.)
| WriteFooter | Writes a footer as produced by the embedded layout's Footer property. (Overrides TextWriterAppender WriteFooter .)
| WriteFooterAndCloseWriter | Writes the footer and closes the underlying TextWriter. (Inherited from TextWriterAppender.)
| WriteHeader | Writes a header produced by the embedded layout's Header property. (Overrides TextWriterAppender WriteHeader .)

Top
Remarks

Logging events are sent to the file specified by the File property.

The file can be opened in either append or overwrite mode by specifying the AppendToFile property. If the file path is relative it is taken as relative from the application base directory. The file encoding can be specified by setting the Encoding property.

The layout's Header and Footer values will be written each time the file is opened and closed respectively. If the AppendToFile property is
then the file may contain multiple copies of the header and footer.

This appender will first try to open the file for writing when ActivateOptions
is called. This will typically be during configuration. If the file cannot be opened for writing the appender will attempt to open the file again each time a message is logged to the appender. If the file cannot be opened for writing when a message is logged then the message will be discarded by this appender.

The FileAppender supports pluggable file locking models via the LockingModel property. The default behavior, implemented by FileAppender
ExclusiveLock is to obtain an exclusive write lock on the file until this appender is closed. The alternative models only hold a write lock while the appender is writing a logging event (FileAppender
MinimalLock) or synchronize by using a named system wide Mutex (FileAppender
InterProcessLock).

All locking strategies have issues and you should seriously consider using a different strategy that avoids having multiple processes logging to the same file.

See Also

#### Reference

log4net.Appender Namespace