public async Task GivenSaveAuthenticationLog_WhenCorrectAuthenticationLogDataIsReceived_ThenShouldPersistLog()
        {
            var options = SqliteInMemory.CreateOptions <LoggingDbContext>();

            await using var context = new LoggingDbContext(options);
            {
                await context.Database.EnsureCreatedAsync();

                context.SeedAuthenticationLogs();

                var authenticationLog = new AuthenticationLog
                {
                    UserId      = "001",
                    MessageType = "UserRegisteredEvent",
                    Timestamp   = DateTime.Now,
                };

                var authenticationLogCount = context.AuthenticationLogs.Count();
                var loggingRepository      = new AuthenticationLogRepository(context);
                await loggingRepository.SaveAuthenticationLog(authenticationLog);

                var updatedAuthenticationLogCount = context.AuthenticationLogs.Count();

                Assert.Equal(authenticationLogCount + 1, updatedAuthenticationLogCount);
            }
        }
예제 #2
0
        private static void SeedInternalErrorLogEntries(LoggingDbContext context)
        {
            if (!context.InternalErrorLogEntries.Any())
            {
                context.InternalErrorLogEntries.AddRange(InternalErrorLogEntryFaker.Generate());
            }

            if (!context.AccountLogEntries.Any())
            {
                context.AccountLogEntries.AddRange(AccountLogEntryFaker.Generate());
            }

            if (!context.PaymentLogEntries.Any())
            {
                context.PaymentLogEntries.AddRange(PaymentLogEntryFaker.Generate());
            }

            if (!context.SearchQueryLogEntries.Any())
            {
                context.SearchQueryLogEntries.AddRange(SearchQueryLogEntryFaker.Generate());
            }

            if (!context.TicketActionLogEntries.Any())
            {
                context.TicketActionLogEntries.AddRange(TicketActionLogEntryFaker.Generate());
            }

            if (!context.TicketDealLogEntries.Any())
            {
                context.TicketDealLogEntries.AddRange(TicketDealLogEntryFaker.Generate());
            }

            context.SaveChanges();
        }
        public async Task GivenSaveErrorLog_WhenCorrectDataReceived_ThenShouldPersistLog()
        {
            var options = SqliteInMemory.CreateOptions <LoggingDbContext>();

            await using var context = new LoggingDbContext(options);
            {
                await context.Database.EnsureCreatedAsync();

                context.SeedSingleErrorLog();

                var errorLog = new ErrorLog
                {
                    ErrorMessage = "Test ErrorCode Message",
                    MessageType  = "ErrorLog",
                    Timestamp    = DateTime.Now,
                    UserId       = "1010101"
                };

                var currentErrorLogCount = context.ErrorLogs.Count();
                var errorLogRepository   = new ErrorLogRepository(context);

                await errorLogRepository.SaveErrorLog(errorLog);

                var updatedErrorLogCount = context.ErrorLogs.Count();

                Assert.Equal(currentErrorLogCount + 1, updatedErrorLogCount);
            }
        }
예제 #4
0
        private void Start()
        {
            LoggingEventEntity[] entities;
            lock (_lock)
            {
                entities = _loggingEvents.ToArray();
                _loggingEvents.Clear();
            }

            try
            {
                using var context = new LoggingDbContext();
                context.Events.AddRange(entities);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                try
                {
                    _logger.Value.LogError(e, "Error while Saving Log-Entitys");
                }
                catch
                {
                    // ignored
                }
            }
        }
예제 #5
0
파일: DbLogger.cs 프로젝트: AgaStarRep/moto
 public DbLogger(LoggingDbContext db, IEnumerable <ILoggerDataProvider> dataProviders, ILogger <DbLogger> aspCoreLogger, IOptionsSnapshot <LoggerOptions> logggerOptions)
 {
     _db            = db;
     _dataProviders = dataProviders;
     _aspCoreLogger = aspCoreLogger;
     _options       = logggerOptions.Value;
 }
 public apiController(LakeLabDbContext context, LoggingDbContext logginContext, ValueStorage vs, DeviceStorage ds)
 {
     _dbContext        = context;
     _loggingDbContext = logginContext;
     _valueStorage     = vs;
     _deviceStorage    = ds;
 }
        public async Task Invoke(HttpContext httpContext, LoggingDbContext context)
        {
            if (httpContext.User.Identity.IsAuthenticated && httpContext.User.IsInRole("Users"))
            {
                context.UserRequests.Add(new Models.UserRequest(httpContext.User.Identity.Name, DateTime.Now));
                await context.SaveChangesAsync();
            }

            await _next.Invoke(httpContext);
        }
        private async Task FillDatabase()
        {
            using var db = new LoggingDbContext();

            await db.Events.AddRangeAsync(
                new LoggingEventEntity(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>())),
                new LoggingEventEntity(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>())));

            await db.SaveChangesAsync();
        }
예제 #9
0
        public void Emit_Dispose_Test()
        {
            var testObject = GetTestingObject();

            using (var provider = testObject.GetResolvedTestingObject())
                provider.Emit(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>()));

            using var context = new LoggingDbContext();

            Assert.Equal(1, context.Events.Count());
        }
예제 #10
0
        public void Emit_Autostart_Test()
        {
            var testObject = GetTestingObject();
            var provider   = testObject.GetResolvedTestingObject();

            provider.Emit(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>()));
            provider.Emit(new LogEvent(DateTimeOffset.Now, LogEventLevel.Warning, null, MessageTemplate.Empty, Array.Empty <LogEventProperty>()));

            Thread.Sleep(TimeSpan.FromMilliseconds(5000));

            using var context = new LoggingDbContext();

            Assert.Equal(2, context.Events.Count());
        }
예제 #11
0
        public TestBase()
        {
            var options = new DbContextOptionsBuilder <LoggingDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            Context = new LoggingDbContext(options);

            Context.Database.EnsureCreated();

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfiles(typeof(AccountLogDomainToDbProfile).Assembly);
            });

            Mapper = mockMapper.CreateMapper();
        }
        public async Task GivenGetAllAuthenticationLogs_WhenRequestIsMade_ThenShouldReturnCorrectData()
        {
            var options = SqliteInMemory.CreateOptions <LoggingDbContext>();

            await using var context = new LoggingDbContext(options);
            {
                await context.Database.EnsureCreatedAsync();

                context.SeedSingleAuthenticationLog();

                var loggingRepository = new AuthenticationLogRepository(context);
                var logs = await loggingRepository.GetAllAuthenticationLogs();

                Assert.IsType <List <AuthenticationLog> >(logs);
                Assert.Single(logs);
            }
        }
        [Fact] public async Task GivenGetAllErrorLogs_WhenCalled_ThenShouldReturnAllErrorLogs()
        {
            var options = SqliteInMemory.CreateOptions <LoggingDbContext>();

            await using var context = new LoggingDbContext(options);
            {
                await context.Database.EnsureCreatedAsync();

                context.SeedErrorLogs();

                var errorLogCount      = context.ErrorLogs.Count();
                var errorLogRepository = new ErrorLogRepository(context);

                var logs = await errorLogRepository.GetAllErrorLogs();

                Assert.NotNull(logs);
                Assert.Equal(errorLogCount, logs.Count);
                Assert.IsType <List <ErrorLog> >(logs);
            }
        }
예제 #14
0
 public LogsRepository(LoggingDbContext context)
 {
     _context = context;
 }
예제 #15
0
 public LoggingService(LoggingDbContext dbContext)
 {
     _dbContext = dbContext;
 }
예제 #16
0
 public ErrorLogRepository(LoggingDbContext context)
 {
     _context = context;
 }
예제 #17
0
 public ItemsController(LoggingDbContext context)
 {
     this.context = context;
 }
예제 #18
0
 public LoggingDb(LoggingDbContext context)
 => _context = context;
예제 #19
0
 public SqlLoggingDatabase(LoggingDbContext context, IHubContext <LoggingHub, ILoggingHubService> hubContext)
 {
     _context    = context;
     _hubContext = hubContext;
 }
예제 #20
0
 public CustomLogger(LoggingDbContext loggerDbContext)
 {
     LoggerDbContext = loggerDbContext;
     StartWorker();
 }
예제 #21
0
 public TicketLogService(LoggingDbContext context, IMapper mapper)
     : base(context, mapper)
 {
 }
예제 #22
0
 public SearchLogService(LoggingDbContext context, IMapper mapper)
     : base(context, mapper)
 {
 }
예제 #23
0
 public ErrorLogService(LoggingDbContext context, IMapper mapper)
     : base(context, mapper)
 {
 }
예제 #24
0
 public BaseService(LoggingDbContext context, IMapper mapper)
 {
     Context = context;
     Mapper  = mapper;
 }
예제 #25
0
 public DbLoggingProvider(LoggingDbContext context)
 {
     this.context = context;
 }
예제 #26
0
 public static void SeedAuthenticationLogs(this LoggingDbContext context)
 {
     context.AuthenticationLogs.AddRange(AuthenticationLogs());
     context.SaveChanges();
 }
예제 #27
0
 public static void SeedErrorLogs(this LoggingDbContext context)
 {
     context.ErrorLogs.AddRange(ErrorLogs());
     context.SaveChanges();
 }
예제 #28
0
 public LoggingController(LoggingDbContext loggingDbContext)
 {
     _loggingDbContext = loggingDbContext;
 }
예제 #29
0
 public AccountLogService(LoggingDbContext context, IMapper mapper)
     : base(context, mapper)
 {
 }
예제 #30
0
 public LogsController(LoggingDbContext applicationDbContext, IRepository <Log> logsRepository)
 {
     ApplicationDbContext = applicationDbContext;
     LogsRepository       = logsRepository;
 }