Exemplo n.º 1
0
        public void CheckIfLoggingIsCorrect()
        {
            DbLogging logger = new DbLogging(dbPath);

            Task.Run(async() =>
            {
                await logger.Debug("deb");
                await logger.Error("err");
                await logger.Fatal("fat");
                await logger.Info("inf");
                await logger.Warn("war");
            }).GetAwaiter().GetResult();

            string result1, result2, result3, result4, result5;

            using (LoggingDatabaseContext DbContext = new LoggingDatabaseContext(_connectionString))
            {
                result1 = DbContext.Set <Log>().Find(1).Message;
                result2 = DbContext.Set <Log>().Find(2).Message;
                result3 = DbContext.Set <Log>().Find(3).Message;
                result4 = DbContext.Set <Log>().Find(4).Message;
                result5 = DbContext.Set <Log>().Find(5).Message;
                DbContext.Database.Delete();
            }
            Assert.AreEqual("deb", result1);
            Assert.AreEqual("err", result2);
            Assert.AreEqual("fat", result3);
            Assert.AreEqual("inf", result4);
            Assert.AreEqual("war", result5);
        }
Exemplo n.º 2
0
        public static void AddNpgLoggerScoped(this IServiceCollection services, string connectionString, LogLevel defaultLogLevel)
        {
            var optionsBuilder = new DbContextOptionsBuilder <LoggingDatabaseContext>();

            optionsBuilder.UseNpgsql(connectionString);
            var dbContext         = new LoggingDatabaseContext(optionsBuilder.Options);
            var loggingRepository = new LoggingRepository(dbContext);

            services.AddScoped <INpgLogger>(s => new NpgLogger(loggingRepository, defaultLogLevel));
        }