<commit_before>﻿using System;
using System.Diagnostics;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using log4net.Appender;
using log4net.Core;

namespace AxCommonLogger.Appenders
{
    public class Log4netReactiveForwardingAppender : ForwardingAppender, IDisposable
    {
        protected IDisposable _cleanUp;
        protected EventLoopScheduler _orderedScheduler = new EventLoopScheduler();
        protected ISubject<LoggingEvent[]> _loggingSubject = new Subject<LoggingEvent[]>();

        public Log4netReactiveForwardingAppender()
        {
            IDisposable appender = _loggingSubject.AsObservable()
                                                  .ObserveOn(_orderedScheduler)
                                                  .Where(x => x != null)
                                                  .Subscribe(x => base.Append(x));

            _cleanUp = Disposable.Create(() => { appender.Dispose(); });
        }

        [DebuggerStepThrough]
        protected override void Append(LoggingEvent loggingEvent)
        {
            _loggingSubject.OnNext(new[] {loggingEvent});
        }

        [DebuggerStepThrough]
        protected override void Append(LoggingEvent[] loggingEvents)
        {
            _loggingSubject.OnNext(loggingEvents);
        }

        [DebuggerStepThrough]
        protected override void OnClose()
        {
            _loggingSubject.OnCompleted();
            base.OnClose();
        }

        public void Dispose()
        {
            _cleanUp?.Dispose();
            _cleanUp = null;

            _loggingSubject?.OnCompleted();
            _loggingSubject = null;

            _orderedScheduler?.Dispose();
            _orderedScheduler = null;
        }
    }
}<commit_msg>Added some comments on reactive scheduler<commit_after>﻿using System;
using System.Diagnostics;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using log4net.Appender;
using log4net.Core;

namespace AxCommonLogger.Appenders
{
    public class Log4netReactiveForwardingAppender : ForwardingAppender, IDisposable
    {
        // The EventLoopScheduler preserve order of events on dedicated thread.
        protected EventLoopScheduler _scheduler = new EventLoopScheduler();

        protected ISubject<LoggingEvent> _loggingSubject = new Subject<LoggingEvent>();
        protected IDisposable _cleanUp;

        public Log4netReactiveForwardingAppender()
        {
            IDisposable appender = _loggingSubject.AsObservable()
                                                  .ObserveOn(_scheduler)
                                                  .Where(x => x != null)
                                                  .Subscribe(base.Append);

            _cleanUp = Disposable.Create(() => { appender.Dispose(); });
        }

        [DebuggerStepThrough]
        protected override void Append(LoggingEvent loggingEvent)
        {
            _loggingSubject.OnNext(loggingEvent);
        }

        [DebuggerStepThrough]
        protected override void Append(LoggingEvent[] loggingEvents)
        {
            foreach (LoggingEvent loggingEvent in loggingEvents)
            {
                _loggingSubject.OnNext(loggingEvent);
            }
        }

        [DebuggerStepThrough]
        protected override void OnClose()
        {
            _loggingSubject.OnCompleted();
            base.OnClose();
        }

        public void Dispose()
        {
            _cleanUp?.Dispose();
            _cleanUp = null;

            _loggingSubject?.OnCompleted();
            _loggingSubject = null;

            _scheduler?.Dispose();
            _scheduler = null;
        }
    }
}
{'fraction_non_alphanumeric': 0.07954843791021265, 'fraction_numerical': 0.002100288789708585, 'mean_word_length': 1.9039634146341464, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5136761', 'n_tokens_mistral': 942, 'n_tokens_neox': 917, 'n_words': 185}