public void TestKeyReservation() { lock (_keyReservations) { _keyReservations.Clear(); _prefixReservations.Clear(); } Guid reservation = Guid.NewGuid(); string key = "My test key"; string key2 = LogContext.ReserveKey(key, reservation); Assert.AreEqual(key, key2); Guid r2; Assert.IsTrue(_keyReservations.TryGetValue(key, out r2)); Assert.AreEqual(reservation, r2); string value = Tester.RandomGenerator.RandomString(); LogContext context = new LogContext(); context.Set(reservation, key, value); Assert.IsNotNull(context); string value2 = context.Get(key); Assert.AreEqual(value, value2); }
public async Task TestMemoryLogger() { Log.CacheMaximum = 1000; Log.CacheExpiry = TimeSpan.FromMinutes(1); Log.ValidLevels = LoggingLevels.All; string message = "Test message " + Guid.NewGuid(); LogContext context = new LogContext(); context.Set("My data", 1); context.Set("Some more", "Test"); Log.Add(context, LoggingLevel.Notification, message); await Log.Flush(); List <Log> logs = Log.AllCached.ToList(); Assert.IsNotNull(logs); Assert.IsTrue(logs.Any(), "No logs found!"); Assert.IsTrue(logs.Any(l => l.Message == message), "No log with the message '{0}' found.", message); }
public void OnNext(IEnumerable <StatisticEvent> value) { using (var context = new LogContext()) { foreach (var statisticEvent in value) { context.Set <StatisticEvent>().Add(statisticEvent); } context.SaveChanges(); } }
public void OnNext(IEnumerable<StatisticEvent> value) { using(var context = new LogContext()) { foreach (var statisticEvent in value) { context.Set<StatisticEvent>().Add(statisticEvent); } context.SaveChanges(); } }
public async Task <int> Put(User user) { var userTracker = _ctx.Set <User>().Local .FirstOrDefault(entry => entry.UserId.Equals(user.UserId)); if (userTracker != null) { _ctx.Entry(userTracker).State = EntityState.Detached; } _ctx.Entry(user).State = EntityState.Modified; _ctx.Entry(user).Property("Password").IsModified = false; _ctx.Entry(user).Property("CreatedDate").IsModified = false; user.UpdatedDate = DateTime.Now; await _ctx.SaveChangesAsync(); return(user.UserId); }
public void TestKeyReservationErrors() { lock (_keyReservations) { _keyReservations.Clear(); _prefixReservations.Clear(); } Guid reservation = Guid.NewGuid(); string key = Tester.RandomGenerator.RandomString(LogContext.MaximumKeyLength); string key2 = LogContext.ReserveKey(key, reservation); Assert.AreEqual(key, key2); Guid r2; Assert.IsTrue(_keyReservations.TryGetValue(key, out r2)); Assert.AreEqual(reservation, r2); string value = Tester.RandomGenerator.RandomString(); LogContext context = new LogContext(); context.Set(key, value); }
public static void SetContext(this ILogger logger, LogContext context) { context.Set(logger); }
/// <summary> /// Returns logs for predicate. /// </summary> /// <param name="predicate">Condition</param> /// <returns>Logs</returns> public IEnumerable <T> Find(Func <T, bool> predicate) { return(_context.Set <T>().Where(predicate)); }
public override void Add(Log item) { ldb.Set <Log>().Add(item); Save(); }
public async Task <TEntity> Get(Expression <Func <TEntity, bool> > filter = null) { return(await _ctx.Set <TEntity>().FirstOrDefaultAsync(filter)); }
public PostgresRepository(LogContext context) { Db = context; DbSet = Db.Set <TEntity>(); }