コード例 #1
0
        public void TestCleanup()
        {
            var context = new AuditLogContext(_options);

            context.Set <AuditLogItem>().RemoveRange(context.Set <AuditLogItem>());
            context.SaveChanges();
        }
コード例 #2
0
 protected static void WriteToLog(AuditLog logItem)
 {
     using (var context = new AuditLogContext())
     {
         context.AuditLogs.AddObject(logItem);
         context.SaveChanges();
     }
 }
コード例 #3
0
        private void SeedData()
        {
            using var context = new AuditLogContext(_options);
            var logEntries = new List <LogEntry>
            {
                new LogEntry
                {
                    Timestamp  = new DateTime(2019, 5, 8).Ticks,
                    RoutingKey = "Test.*",
                    EventJson  = "{'title': 'Some title'}",
                    EventType  = "DomainEvent"
                },
                new LogEntry
                {
                    Timestamp  = new DateTime(2019, 7, 2).Ticks,
                    RoutingKey = "Test.#",
                    EventJson  = "{'title': 'Some title'}",
                    EventType  = "DomainEvent"
                },
                new LogEntry
                {
                    Timestamp  = new DateTime(2019, 7, 2).Ticks,
                    RoutingKey = "Test.#",
                    EventJson  = "{'title': 'Some title'}",
                    EventType  = "DomainEvent"
                },
                new LogEntry
                {
                    Timestamp  = new DateTime(2019, 8, 15).Ticks,
                    RoutingKey = "Test2.#",
                    EventJson  = "{'title': 'Some title'}",
                    EventType  = "DomainEvent"
                }
            };

            context.LogEntries.AddRange(logEntries);

            context.SaveChanges();
        }
コード例 #4
0
 /// <summary>
 /// Inject data directly into the context
 /// </summary>
 private void InjectData(params AuditLogItem[] items)
 {
     using var context = new AuditLogContext(_options);
     context.AuditLogItems.AddRange(items);
     context.SaveChanges();
 }
コード例 #5
0
 /// <summary>
 /// Save a log item to the database
 /// </summary>
 public void Save(AuditLogItem item)
 {
     _auditLogContext.AuditLogItems.Add(item);
     _auditLogContext.SaveChanges();
 }