Esempio n. 1
0
        public static IApplicationBuilder UseCoreJobClient(this IApplicationBuilder app, Action <JobLoggerConfiguration> logAction = null)
        {
            app.UseMiddleware <CoreJobClientMiddleware>();

            var jobLoggerConfiguration = new JobLoggerConfiguration();

            logAction?.Invoke(jobLoggerConfiguration);
            var loggerFactory = app.ApplicationServices.GetRequiredService <ILoggerFactory>();

            loggerFactory.AddProvider(new CustomJobLoggerProvider(jobLoggerConfiguration, app.ApplicationServices.GetRequiredService <IJobLoggerStore>()));
            return(app);
        }
        public void ShouldSetFalseValue_WhenItsNotConfigured()
        {
            var appSettings =
                new NameValueConfigurationCollection {
                new NameValueConfigurationElement("JobLogger:LogToFile", "true")
            };

            var loggerConfiguration = new JobLoggerConfiguration(appSettings);

            Assert.True(loggerConfiguration.LogToFile);
            Assert.False(loggerConfiguration.LogToConsole);
            Assert.False(loggerConfiguration.LogToDb);
        }
 public void ShouldThrowException_WhenAllValuesAreFalse() => Assert.Throws <ConfigurationErrorsException>(() =>
 {
     var _ = new JobLoggerConfiguration(new NameValueConfigurationCollection());
 });
 public CustomJobLoggerProvider(JobLoggerConfiguration config, IJobLoggerStore jobLogger)
 {
     _config    = config;
     _jobLogger = jobLogger;
 }