<commit_before>// Copyright (c) MarinAtanasov. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the project root for license information.
//
using AppBrix.Lifecycle;
using AppBrix.Logging.File.Configuration;
using System;
using System.IO;
using System.Linq;

namespace AppBrix.Logging.File
{
    /// <summary>
    /// A log writer which writes entries to the console.
    /// </summary>
    internal sealed class FileLogWriter : ILogWriter
    {
        #region Public and overriden methods
        public void Initialize(IInitializeContext context)
        {
            var config = context.App.GetConfig<FileLoggerConfig>();
            this.writer = System.IO.File.AppendText(config.Path);
        }

        public void Uninitialize()
        {
            this.writer?.Dispose();
            this.writer = null;
        }
        
        public void WriteEntry(ILogEntry entry)
        {
            this.writer.WriteLine(entry.ToString());
        }
        #endregion

        #region Private fields and constants
        private TextWriter writer;
        #endregion
    }
}
<commit_msg>Fixed a race condition with FileLogWriter in sync mode.<commit_after>// Copyright (c) MarinAtanasov. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the project root for license information.
//
using AppBrix.Lifecycle;
using AppBrix.Logging.File.Configuration;
using System;
using System.IO;
using System.Linq;

namespace AppBrix.Logging.File
{
    /// <summary>
    /// A log writer which writes entries to the console.
    /// </summary>
    internal sealed class FileLogWriter : ILogWriter
    {
        #region Public and overriden methods
        public void Initialize(IInitializeContext context)
        {
            var config = context.App.GetConfig<FileLoggerConfig>();
            this.writer = System.IO.File.AppendText(config.Path);
        }

        public void Uninitialize()
        {
            this.writer?.Dispose();
            this.writer = null;
        }
        
        public void WriteEntry(ILogEntry entry)
        {
            lock (this.writer)
            {
                this.writer.WriteLine(entry.ToString());
            }
        }
        #endregion

        #region Private fields and constants
        private TextWriter writer;
        #endregion
    }
}

{'fraction_non_alphanumeric': 0.08887008040626322, 'fraction_numerical': 0.0, 'mean_word_length': 2.0901960784313727, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6189878', 'n_tokens_mistral': 612, 'n_tokens_neox': 612, 'n_words': 180}