Click or drag to resize

FileTarget Class

Writes log messages to one or more files.
Inheritance Hierarchy
SystemObject
  NLog.TargetsTarget
    NLog.TargetsTargetWithLayout
      NLog.TargetsTargetWithLayoutHeaderAndFooter
        NLog.TargetsFileTarget

Namespace:  NLog.Targets
Assembly:  NLog (in NLog.dll) Version: 5.3.4+73d83d3161d31288ca5c554cc50d27b6bed5f28b
Syntax
public class FileTarget : TargetWithLayoutHeaderAndFooter

The FileTarget type exposes the following members.

Constructors
  NameDescription
Public methodFileTarget
Initializes a new instance of the FileTarget class.
Public methodFileTarget(String)
Initializes a new instance of the FileTarget class.
Top
Properties
  NameDescription
Public propertyArchiveAboveSize
Gets or sets the size in bytes above which log files will be automatically archived.
Public propertyArchiveDateFormat
Gets or sets a value specifying the date format to use when archiving files.
Public propertyArchiveEvery
Gets or sets a value indicating whether to automatically archive log files every time the specified time passes.
Public propertyArchiveFileKind
Is the ArchiveFileName an absolute or relative path?
Public propertyArchiveFileName
Gets or sets the name of the file to be used for an archive.
Public propertyArchiveNumbering
Gets or sets the way file archives are numbered.
Public propertyArchiveOldFileOnStartup
Gets or sets a value indicating whether to archive old log file on startup.
Public propertyArchiveOldFileOnStartupAboveSize
Gets or sets a value of the file size threshold to archive old log file on startup.
Public propertyAutoFlush
Gets or sets a value indicating whether to automatically flush the file buffers after each log message.
Public propertyBufferSize
Gets or sets the log file buffer size in bytes.
Public propertyCleanupFileName
Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong.
Public propertyCode exampleConcurrentWriteAttemptDelay
Gets or sets the delay in milliseconds to wait before attempting to write to the file again.
Public propertyConcurrentWriteAttempts
Gets or sets the number of times the write is appended on the file before NLog discards the log message.
Public propertyConcurrentWrites
Gets or sets a value indicating whether concurrent writes to the log file by multiple processes on the same host.
Public propertyCreateDirs
Gets or sets a value indicating whether to create directories if they do not exist.
Public propertyDeleteOldFileOnStartup
Gets or sets a value indicating whether to delete old log file on startup.
Public propertyDiscardAll
Gets or sets whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write
Public propertyEnableArchiveFileCompression
Gets or sets a value indicating whether to compress archive files into the zip archive format.
Public propertyEnableFileDelete
Gets or sets a value indicating whether to enable log file(s) to be deleted.
Public propertyEncoding
Gets or sets the file encoding.
Public propertyFileAttributes
Gets or sets the file attributes (Windows only).
Public propertyStatic memberFileCompressor
Used to compress log files during archiving. This may be used to provide your own implementation of a zip file compressor, on platforms other than .Net4.5. Defaults to ZipArchiveFileCompressor on .Net4.5 and to null otherwise.
Public propertyCode exampleFileName
Gets or sets the name of the file to write to.
Public propertyFileNameKind
Is the FileName an absolute or relative path?
Public propertyFooter
Gets or sets the footer.
(Inherited from TargetWithLayoutHeaderAndFooter.)
Public propertyForceManaged
Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation.
Public propertyForceMutexConcurrentWrites
Gets or sets a value indicating whether file creation calls should be synchronized by a system global mutex.
Public propertyHeader
Gets or sets the header.
(Inherited from TargetWithLayoutHeaderAndFooter.)
Protected propertyIsInitialized
Gets a value indicating whether the target has been initialized.
(Inherited from Target.)
Public propertyKeepFileOpen
Gets or sets a value indicating whether to keep log file open instead of opening and closing it on each logging event.
Public propertyLayout
Gets or sets the text to be rendered.
(Inherited from TargetWithLayoutHeaderAndFooter.)
Public propertyLineEnding
Gets or sets the line ending mode.
Protected propertyLoggingConfiguration
Gets the logging configuration this target is part of.
(Inherited from Target.)
Public propertyMaxArchiveDays
Gets or sets the maximum days of archive files that should be kept.
Public propertyMaxArchiveFiles
Gets or sets the maximum number of archive files that should be kept.
Public propertyName
Gets or sets the name of the target.
(Inherited from Target.)
Protected propertyNewLineChars
Gets the characters that are appended after each line.
Public propertyOpenFileCacheSize
Gets or sets the number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger).
Public propertyOpenFileCacheTimeout
Gets or sets the maximum number of seconds that files are kept open. Zero or negative means disabled.
Public propertyOpenFileFlushTimeout
Gets or sets the maximum number of seconds before open files are flushed. Zero or negative means disabled.
Public propertyReplaceFileContentsOnEachWrite
Gets or sets a value indicating whether to replace file contents on each write instead of appending log message at the end.
Protected propertySyncRoot
Gets the object which can be used to synchronize asynchronous operations that must rely on the .
(Inherited from Target.)
Public propertyWriteBom
Gets or sets a value indicating whether to write BOM (byte order mark) in created files. Defaults to true for UTF-16 and UTF-32
Public propertyWriteFooterOnArchivingOnly
Gets or sets a value indicating whether the footer should be written only when the file is archived.
Public propertyWriteHeaderWhenInitialFileNotEmpty
Gets or sets whether to write the Header on initial creation of file appender, even if the file is not empty. Default value is , which means only write header when initial file is empty (Ex. ensures valid CSV files)
Top
Methods
  NameDescription
Public methodStatic memberCalculateNextWeekday
Calculate the DateTime of the requested day of the week.
Public methodCleanupInitializedFiles
Removes records of initialized files that have not been accessed in the last two days.
Public methodCleanupInitializedFiles(DateTime)
Removes records of initialized files that have not been accessed after the specified date.
Protected methodCloseTarget
Closes the file(s) opened for writing.
(Overrides TargetCloseTarget.)
Public methodDispose
Closes the target.
(Inherited from Target.)
Protected methodDispose(Boolean)
Releases unmanaged and - optionally - managed resources.
(Inherited from Target.)
Public methodFlush
Flush any pending log messages (in case of asynchronous targets).
(Inherited from Target.)
Protected methodFlushAsync
Flushes all pending file operations.
(Overrides TargetFlushAsync(AsyncContinuation).)
Protected methodInitializeTarget
Initializes file logging by creating data structures that enable efficient multi-file logging.
(Overrides TargetInitializeTarget.)
Public methodPrecalculateVolatileLayouts
Calls the Precalculate(LogEventInfo) on each volatile layout used by this target. This method won't prerender if all layouts in this target are thread-agnostic.
(Inherited from Target.)
Protected methodRenderFormattedMessage
Formats the log event for write.
Protected methodRenderFormattedMessageToStream
Gets the bytes to be written to the file.
Protected methodRenderLogEvent(Layout, LogEventInfo)
Renders the logevent into a string-result using the provided layout
(Inherited from Target.)
Protected methodRenderLogEventT(LayoutT, LogEventInfo, T)
Renders the logevent into a result-value by using the provided layout
(Inherited from Target.)
Protected methodResolveServiceT
Resolve from DI ServiceRepository
(Inherited from Target.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Target.)
Protected methodTransformStream
Modifies the specified byte array before it gets sent to a file.
Protected methodWrite(AsyncLogEventInfo)
Writes async log event to the log target.
(Inherited from Target.)
Protected methodWrite(IListAsyncLogEventInfo)
Writes the specified array of logging events to a file specified in the FileName parameter.
(Overrides TargetWrite(IListAsyncLogEventInfo).)
Protected methodWrite(LogEventInfo)
Writes the specified logging event to a file specified in the FileName parameter.
(Overrides TargetWrite(LogEventInfo).)
Public methodWriteAsyncLogEvent
Writes the log to the target.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(AsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Public methodWriteAsyncLogEvents(IListAsyncLogEventInfo)
Writes the array of log events.
(Inherited from Target.)
Protected methodWriteAsyncThreadSafe(AsyncLogEventInfo)
Writes a log event to the log target, in a thread safe manner. Any override of this method has to provide their own synchronization mechanism. !WARNING! Custom targets should only override this method if able to provide their own synchronization mechanism. Layout-objects are not guaranteed to be thread-safe, so using them without a SyncRoot-object can be dangerous.
(Inherited from Target.)
Protected methodWriteAsyncThreadSafe(IListAsyncLogEventInfo)
Writes an array of logging events to the log target, in a thread safe manner. Any override of this method has to provide their own synchronization mechanism. !WARNING! Custom targets should only override this method if able to provide their own synchronization mechanism. Layout-objects are not guaranteed to be thread-safe, so using them without a SyncRoot-object can be dangerous.
(Inherited from Target.)
Protected methodWriteFailedNotInitialized
LogEvent is written to target, but target failed to successfully initialize
(Inherited from Target.)
Top
Remarks
See Also