Пример #1
0
        public AsyncLOGInstance(bool spawnWorkerThread = true, SyncType synchroniser = SyncType.None, bool singletonMode = false, IEnumerable <ILogOutput> outputters = null, IEnumerable <KeyValuePair <string, string> > additionalFields = null)
        {
            //Setting up the Singleton if requested by the user
            if (singletonMode)
            {
                _singleton = true;
                LOG.SetupSingleton(this);
            }

            //Coppying the requested output types or creating a new default Console logger
            if (outputters == null)
            {
                _outputters.Add(new ConsoleOutputter());
            }
            else
            {
                _outputters.AddRange(outputters);
            }
            //Initializing the Log OutPutters
            foreach (ILogOutput outputter in _outputters)
            {
                outputter.Initialize();
            }
            //setting up the Worker thread if requested by the user
            _synchroniser = synchroniser;
            if (spawnWorkerThread)
            {
                _shouldRun    = true;
                _workerThread = new Thread(ThreadRunner);
                _waiter       = new EventWaitHandle(false, EventResetMode.AutoReset);
                _workerThread.Start();
            }
            //Prepairing the additional fields witch get added to every logMessage
            if (additionalFields == null)
            {
                return;
            }
            foreach (KeyValuePair <string, string> additionalField in additionalFields)
            {
                _additionalFields.Add(additionalField.Key, additionalField.Value);
            }
        }