Exemplo n.º 1
0
 public DLogger(string category, Func <string, LogLevel, bool> filter, ILogWriter writer, ILoggerSettings settings)
 {
     _writer  = writer;
     _filter  = filter;
     Category = category;
     Settings = settings;
 }
Exemplo n.º 2
0
 private void OnConfigurationReload(object state)
 {
     try
     {
         // The settings object needs to change here, because the old one is probably holding on
         // to an old change token.
         _settings = _settings.Reload();
         var includeScopes = _settings?.IncludeScopes ?? false;
         foreach (var logger in _loggers.Values)
         {
             logger.Filter        = GetFilter(logger.CategoryName, _settings);
             logger.IncludeScopes = includeScopes;
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error while loading configuration changes.{Environment.NewLine}{ex}");
     }
     finally
     {
         // The token will change each time it reloads, so we need to register again.
         if (_settings?.ChangeToken != null)
         {
             _settings.ChangeToken.RegisterChangeCallback(OnConfigurationReload, null);
         }
     }
 }
Exemplo n.º 3
0
        public Settings(
            string sourceRoot,
            ILocation destinationRoot,
            IRateLimiterSettings rateLimiterSettings = null,
            ILoggerSettings loggerSettings           = null,
            IGifSettings gifSettings   = null,
            IJpegSettings jpegSettings = null,
            IPngSettings pngSettings   = null)
        {
            if (string.IsNullOrEmpty(sourceRoot))
            {
                throw new ArgumentException("SourceRoot must be set.", "sourceRoot");
            }

            if (destinationRoot == null)
            {
                throw new ArgumentException("DestinationRoot must be set.", "destinationRoot");
            }

            SourceRoot          = sourceRoot;
            DestinationRoot     = destinationRoot;
            RateLimiterSettings = rateLimiterSettings ?? new RateLimiterSettings();
            LoggerSettings      = loggerSettings ?? new LoggerSettings();
            GifSettings         = gifSettings ?? new GifSettings();
            JpegSettings        = jpegSettings ?? new JpegSettings();
            PngSettings         = pngSettings ?? new PngSettings();
        }
        /// <summary>
        /// Apply external settings to the logger configuration.
        /// </summary>
        /// <returns>Configuration object allowing method chaining.</returns>
        public LoggerConfiguration Settings(ILoggerSettings settings)
        {
            if (settings == null) throw new ArgumentNullException("settings");

            settings.Configure(_loggerConfiguration);

            return _loggerConfiguration;
        }
Exemplo n.º 5
0
 public AbstractLoggerTests()
 {
     _loggerSettings = Substitute.For <ILoggerSettings>();
     _loggerSettings.MessageFormat.Returns("{0}\t{1:yyyy-MM-dd_HH:mm}:\t{2}");
     _logWriter = Substitute.For <ILogWriter>();
     _logWriter.WriteMessageAsync(Arg.Any <string>(), Arg.Any <LogLevel>()).Returns(Task.CompletedTask);
     _logger = new AbstractLoggerUnderTest(_loggerSettings, _logWriter);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="DatabaseLogger"/> class calling the constructor on <see cref="DatabaseLogger"/>.
 /// This will attempt to create the table in the database if not yet created and <paramref name="createTable"/> is true.
 /// </summary>
 public SqlLogger(ILoggerSettings loggerSettings, ICorrelationIdHelper correlationIdHelper, bool createTable)
     : this(loggerSettings, correlationIdHelper)
 {
     if (createTable)
     {
         CreateTable();
     }
 }
Exemplo n.º 7
0
 internal override void Initialize(ILoggerSettings settings, string applicationName)
 {
     base.Initialize(settings, applicationName);
     _logsDirectory = ((IFileLoggerSettings)settings).LogsDirectory.GetDirectory();
     if (!_logsDirectory.Exists)
     {
         _logsDirectory.Create();
     }
 }
        public void Add_Logger_provider_into_a_new_configuration_manager()
        {
            ILoggerConfigManager configmanager = GetaTestConfigManager(_configPath);
            ILoggerSettings      settings      = configmanager.Load();

            settings.setEnvironment(_environmentName);
            settings.addProvider(GetaTestProvider(_testprovidername));
            Assert.That(settings.getProvider(_testprovidername), !Is.Null);
        }
        /// <summary>
        /// Apply external settings to the logger configuration.
        /// </summary>
        /// <returns>Configuration object allowing method chaining.</returns>
        /// <exception cref="ArgumentNullException">When <paramref name="settings"/> is <code>null</code></exception>
        public LoggerConfiguration Settings(ILoggerSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            settings.Configure(_loggerConfiguration);
            return(_loggerConfiguration);
        }
Exemplo n.º 10
0
 public QuickLoggerService(string setttingsAsJson) : this()
 {
     _configManager = new QuickLoggerStringConfigManager(setttingsAsJson);
     _settings      = _configManager.Load();
     foreach (var provider in _settings.Providers())
     {
         _quicklogger?.AddProvider(provider);
     }
     InitMessage();
 }
Exemplo n.º 11
0
 public LoggerProvider(ILoggerSettings settings, ILogService logService)
 {
     _logService    = logService;
     _settings      = settings ?? throw new ArgumentNullException(nameof(settings));
     _includeScopes = settings.IncludeScopes;
     if (_settings.ChangeToken != null)
     {
         _settings.ChangeToken.RegisterChangeCallback(OnConfigurationReload, null);
     }
 }
Exemplo n.º 12
0
        public LoggerProvider(ILoggerSettings settings, ILogWriter writer)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _settings = settings;
            _writer   = writer;
        }
Exemplo n.º 13
0
        public void Make_default_settings_and_save_to_disk()
        {
            ILoggerConfigManager configmanager = GetaTestConfigManager(_configPath);
            ILoggerSettings      settings      = configmanager.Load();

            settings.setEnvironment(_environmentName);
            settings.addProvider(GetaTestProvider(_testprovidername));
            configmanager.Write();
            Assert.That(File.Exists(_configPath), Is.True);
        }
Exemplo n.º 14
0
        public InstanceLogger(string appKey, ILoggerSettings settings, ToastServiceZone zone = ToastServiceZone.REAL)
        {
            _appKey = appKey;

            var uri        = ToastUri.Create("logger", new ToastUri.VariableSegment(appKey), "initialize");
            var methodCall = MethodCall.CreateSyncCall(uri);

            methodCall.AddParameter("projectKey", appKey)
            .AddParameter("serviceZone", zone.ToString())
            .AddParameter("setting", settings.SettingName.ToUpper());
            ToastNativeSender.SyncSendMessage(methodCall);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DLoggerProvider"/> class
        /// </summary>
        /// <param name="settings"><see cref="ILoggerSettings"/> implementation instance</param>
        /// <param name="writer"><see cref="ILogWriter"/> implementation instance</param>
        /// <exception cref="ArgumentNullException">If the passed <see cref="ILoggerSettings"/> instance is null</exception>
        public DLoggerProvider(ILoggerSettings settings, ILogWriter writer)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            _settings = settings;
            _writer   = writer;
            LogRecordCache.SetCapacity(_settings.BulkWriteCacheSize);

            _settings.ChangeToken?.RegisterChangeCallback(OnConfigurationReload, null);
        }
Exemplo n.º 16
0
        public void Create_Save_And_Load_logger_configuration_from_disk()
        {
            ILoggerConfigManager configmanager = GetaTestConfigManager(_configPath);
            ILoggerSettings      settings      = configmanager.Load();

            settings.setEnvironment(_environmentName);
            settings.addProvider(GetaTestProvider(_testprovidername));
            configmanager.Write();
            Assert.That(File.Exists(_configPath), Is.True);
            Assert.That(configmanager.Reset(), Is.Null);
            settings = configmanager.Load();
            Assert.That(settings, !Is.Null);
            Assert.That(settings.getProvider(_testprovidername), !Is.Null);
        }
Exemplo n.º 17
0
        public FileBaseLogger(IHostingEnvironment hostingEnvironment, ILoggerSettings loggerSetting)
        {
            _hostingEnvironment = hostingEnvironment;
            _loggerSetting      = loggerSetting;

            Basedir     = hostingEnvironment.ContentRootPath + "\\Logs\\";
            _todaysDate = DateTime.Now.ToString("yyyy_MM_dd");

            if (!Directory.Exists(Basedir))
            {
                Directory.CreateDirectory(Basedir);
            }
            LogFilePath = Basedir + _todaysDate + ".log";
            InitLogger();
        }
Exemplo n.º 18
0
        static void Main(string[] args)
        {
            ILoggerConfigManager configManager = new QuickLoggerFileConfigManager(_configName);
            ILoggerSettings      settings      = configManager.Load();

            foreach (ILoggerProvider provider in _providers)
            {
                if (provider.getProviderProperties().GetProviderType() == "ConsoleProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_consoleproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "FileProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_fileproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "RedisProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_redisproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "SlackProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_slackproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "RestProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_restproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "EmailProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_emailproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "AdoProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_adoproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "WindowsEventProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_windowseventlogproviderinfo);
                }
                else if (provider.getProviderProperties().GetProviderType() == "SyslogProvider")
                {
                    provider.getProviderProperties().SetProviderInfo(_syslogproviderinfo);
                }
                settings.addProvider(provider);
            }
            configManager.Write();
        }
Exemplo n.º 19
0
        private Func <string, LogLevel, bool> GetFilter(string name, ILoggerSettings settings)
        {
            if (_filter != null)
            {
                return(_filter);
            }

            if (settings != null)
            {
                foreach (var prefix in GetKeyPrefixes(name))
                {
                    if (settings.TryGetSwitch(prefix, out LogLevel level))
                    {
                        return((n, l) => l >= level);
                    }
                }
            }

            return(falseFilter);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="StringLogger"/> class.
 /// </summary>
 protected VeryPrimitiveLogger(ILoggerSettings loggerSettings, ICorrelationIdHelper correlationIdHelper, ITelemetryHelper telemetryHelper)
 {
     LoggerSettings      = loggerSettings;
     CorrelationIdHelper = correlationIdHelper;
     TelemetryHelper     = telemetryHelper;
     if (TelemetryHelper == null)
     {
         if (loggerSettings.UseApplicationInsightTelemetryHelper)
         {
             TelemetryHelper = (ITelemetryHelper)Activator.CreateInstanceFrom("cdmdotnet.Logging.Azure.ApplicationInsights.dll", "cdmdotnet.Logging.Azure.ApplicationInsights.TelemetryHelper").Unwrap();
         }
         else
         {
             TelemetryHelper = new NullTelemetryHelper();
         }
     }
     ExclusionNamespaces = new SynchronizedCollection <string> {
         "cdmdotnet.Logging"
     };
     InprogressThreads = new SynchronizedCollection <Guid>();
 }
        private void OnConfigurationReload(object state)
        {
            // Creating a new settings object, because the old one is probably holding on to an old change token.
            _settings = _settings.Reload();

            if (!LogRecordCache.IsEmpty)
            {
                LogRecordCache.Flush(_writer);
            }

            LogRecordCache.SetCapacity(_settings.BulkWriteCacheSize);

            foreach (var logger in _loggers.Values)
            {
                logger.Filter   = GetFilter(logger.Category);
                logger.Settings = _settings;
            }

            // The token will change each time it reloads, so we need to register again.
            _settings?.ChangeToken?.RegisterChangeCallback(OnConfigurationReload, null);
        }
Exemplo n.º 22
0
 public QuickLoggerService(ILoggerSettingsPathFinder loggerSettingsPathFinder, IAdditionalLoggerInfoProviderService additionalInfoProvider = null) : this()
 {
     _loggerSettingsPathFinder     = loggerSettingsPathFinder;
     _additionalLoggerInfoProvider = additionalInfoProvider;
     _settings = LoadConfigFromDisk();
     foreach (var provider in _settings.Providers())
     {
         try
         {
             var providername = String.Format("[Name : {0}] - [PID : {1}] - [GUID : {2}]", provider.getProviderProperties().GetProviderName(),
                                              System.Diagnostics.Process.GetCurrentProcess().Id, Guid.NewGuid().ToString());
             provider.getProviderProperties().SetProviderName(providername);
             _quicklogger?.AddProvider(provider);
         }
         catch (Exception ex)
         {
             //TODO : Turrican -> Do something with this! Case provider cannot be added...
         }
     }
     InitMessage();
 }
Exemplo n.º 23
0
 public Logger(ILoggerSettings settings)
 {
     _settings = settings;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Adds a custom logging provider
 /// </summary>
 /// <param name="factory">This <see cref="ILoggerFactory"/> instance</param>
 /// <param name="settings">Logger settings as a <see cref="ILoggerSettings"/> implementation</param>
 /// <param name="writer"><see cref="ILogWriter"/> implementation</param>
 /// <returns>Updated <see cref="ILoggerFactory"/> instance</returns>
 public static ILoggerFactory AddDLogger(this ILoggerFactory factory, ILoggerSettings settings, ILogWriter writer)
 {
     factory.AddProvider(new DLoggerProvider(settings, writer));
     return(factory);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="DatabaseLogger"/> class calling the constructor on <see cref="DatabaseLogger"/>.
 /// </summary>
 public SqlLogger(ILoggerSettings loggerSettings, ICorrelationIdHelper correlationIdHelper, ITelemetryHelper telemetryHelper = null)
     : base(loggerSettings, correlationIdHelper, telemetryHelper)
 {
 }
Exemplo n.º 26
0
 public DefaultLogProvider(IHostingEnvironment hostingEnvironment, ILoggerSettings loggerSetting)
 {
     _hostingEnvironment = hostingEnvironment;
     _loggerSetting      = loggerSetting;
 }
Exemplo n.º 27
0
 public ILoggerSettings Reset()
 {
     _settings = null;
     return(_settings = new QuickLoggerSettings());
 }
Exemplo n.º 28
0
 public ILoggerSettings GetSettings()
 {
     return(_settings ?? (_settings = new QuickLoggerSettings()));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="Logger"/> class preparing the required thread pool polling if <see cref="ILoggerSettings.EnableThreadedLogging"/> is set to true.
 /// </summary>
 protected Logger(ILoggerSettings loggerSettings, ICorrelationIdHelper correlationIdHelper, ITelemetryHelper telemetryHelper)
     : base(loggerSettings, correlationIdHelper, telemetryHelper)
 {
 }
Exemplo n.º 30
0
 /// <summary>
 /// Initializes a new <see cref="ConsoleLogger"/>.
 /// </summary>
 /// <param name="loggerSettings">An <see cref="ILoggerSettings"/>.</param>
 /// <exception cref="ArgumentNullException"><paramref name="loggerSettings"/></exception>
 public ConsoleLogger(ILoggerSettings loggerSettings)
 {
     _LoggerSettings = loggerSettings ?? throw new ArgumentNullException(nameof(loggerSettings));
 }
Exemplo n.º 31
0
 public LoggerSettings(ILoggerSettings loggerSettings) : this(loggerSettings?.LogLevel)
 {
 }
		public ReadFromSettingsCommand( ILoggerSettings settings )
		{
			Settings = settings;
		}