Exemplo n.º 1
0
        private void ReloadFormatters(FileLoggerOptions options)
        {
            this.formatters.TryGetValue(this.options.CurrentValue.FormatterName, out var logFormatter);

            UpdateFormatterOptions(logFormatter, options);

            foreach (KeyValuePair <string, FileLogger> logger in this.loggers)
            {
                logger.Value.Formatter = logFormatter;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Allows setting formatter setting from parent
 /// </summary>
 /// <param name="formatter"></param>
 /// <param name="easyOptions"></param>
 private void UpdateFormatterOptions(FileFormatter formatter, FileLoggerOptions easyOptions)
 {
     // kept for deprecated apis:
     if (formatter is SimpleFileFormatter defaultFormatter)
     {
         defaultFormatter.FormatterOptions.IncludeScopes = defaultFormatter.FormatterOptions.IncludeScopes ?? easyOptions.IncludeScopes;
     }
     if (formatter is JsonFileFormatter jsonFormatter)
     {
         jsonFormatter.FormatterOptions.IncludeScopes = jsonFormatter.FormatterOptions.IncludeScopes ?? easyOptions.IncludeScopes;
     }
 }
        public FileLoggerProcessor(FileLoggerOptions initialOptions, int maxMessageQueuedMessage = 1024)
        {
            _messageQueue = new BlockingCollection <LogMessageEntry>(maxMessageQueuedMessage);

            ConfigureWriter(initialOptions);

            // Start file message queue processor
            _outputThread = new Thread(ProcessLogQueue)
            {
                IsBackground = true,
                Name         = "File logger queue processing thread"
            };
            _outputThread.Start();
        }
        // this needs to be called before the
        public void ConfigureWriter(FileLoggerOptions options)
        {
            try
            {
                // if the file path didn't change, just update the limits
                if (this._writer != null && this._writer?.FilePath == options.ExpandedPath)
                {
                    this._writer.SetLimits(options.MaxFileSizeInBytes, options.MaxNumberFiles);
                }
                else
                {
                    // else swap out the writer and close the old one
                    var newWriter = new FileWriter(options.ExpandedPath, options.MaxFileSizeInBytes, options.MaxNumberFiles, options.Append);

                    FileWriter oldWriter = Interlocked.Exchange(ref this._writer, newWriter) as FileWriter;

                    oldWriter?.Close();
                }
            }
            catch (Exception writerError)
            {
                System.Diagnostics.Trace.TraceError($"Error creating file writer: {writerError.ToString()}");
            }
        }
Exemplo n.º 5
0
 private void ReloadLoggerOptions(FileLoggerOptions options)
 {
     this.messageQueue.ConfigureWriter(options);
     ReloadFormatters(options);
 }