NLog.Targets.FileTarget.WriteToFile C# (CSharp) Method

WriteToFile() private method

Evaluates which parts of a file should be written (header, content, footer) based on various properties of FileTarget instance and writes them.
private WriteToFile ( string fileName, LogEventInfo logEvent, byte bytes, bool justData ) : void
fileName string File name to be written.
logEvent LogEventInfo Log event that the instance is currently processing.
bytes byte Raw sequence of to be written into the content part of the file.
justData bool Indicates that only content section should be written in the file.
return void
        private void WriteToFile(string fileName, LogEventInfo logEvent, byte[] bytes, bool justData)
        {
            if (this.ReplaceFileContentsOnEachWrite)
            {
                ReplaceFileContent(fileName, bytes, true);
                return;
            }

            bool writeHeader = InitializeFile(fileName, logEvent, justData);
            BaseFileAppender appender = this.fileAppenderCache.AllocateAppender(fileName);

            try
            {
                if (writeHeader)
                {
                    this.WriteHeader(appender);
                }

                appender.Write(bytes);

                if (this.AutoFlush)
                {
                    appender.Flush();
                }
            }
            catch (Exception ex)
            {
                InternalLogger.Error(ex, "Failed write to file '{0}'.", fileName);
                this.fileAppenderCache.InvalidateAppender(fileName);
                throw;
            }
        }