public void Starting_is_no_op_if_already_started_and_likewise_for_stopping() { using (var context = new SimpleModelContext()) { var output = CaptureConsoleOutput( () => { using (var logger = new DatabaseLogger()) { logger.StopLogging(); context.Products.ToArray(); logger.StartLogging(); logger.StartLogging(); context.Categories.ToArray(); logger.StopLogging(); logger.StopLogging(); context.Products.ToArray(); } }); Assert.Contains("FROM [dbo].[Categories]", output); Assert.DoesNotContain("FROM [dbo].[Products]", output); } }
public void Logging_can_be_started_and_stopped() { using (var context = new SimpleModelContext()) { var output = CaptureConsoleOutput( () => { using (var logger = new DatabaseLogger()) { context.Products.ToArray(); logger.StartLogging(); logger.StopLogging(); context.Products.ToArray(); logger.StartLogging(); context.Categories.ToArray(); logger.StopLogging(); context.Products.ToArray(); } }); var foundIndex = output.IndexOf("FROM [dbo].[Categories]"); Assert.True(foundIndex > 0); foundIndex = output.IndexOf("FROM [dbo].[Categories]", foundIndex + 1); Assert.Equal(-1, foundIndex); Assert.DoesNotContain("FROM [dbo].[Products]", output); } }
public AutoLotEntities() : base("name=AutoLotConnection") { //DbInterception.Add(new ConsoleWriterInterceptor()); dbLogger.StartLogging(); DbInterception.Add(dbLogger); var context = (this as IObjectContextAdapter).ObjectContext; context.SavingChanges += OnSavingChanges; }
public void DatabaseLogger_can_append_to_a_file() { using (var context = new SimpleModelContext()) { var output = CaptureFileOutput( f => { using (var logger = new DatabaseLogger(f, append: false)) { logger.StartLogging(); context.Categories.ToArray(); } using (var logger = new DatabaseLogger(f, append: true)) { logger.StartLogging(); context.Products.ToArray(); } }); Assert.Contains("FROM [dbo].[Categories]", output); Assert.Contains("FROM [dbo].[Products]", output); } }
public AutoLotEntities() : base("name=AutoLotConnection") { //DbInterception.Add(new ConsoleWriterInterceptor()); DatabaseLogger.StartLogging(); DbInterception.Add(DatabaseLogger); }
public UserDataContext() : base("UserData") { if (DbLogger.IsActive) { DatabaseLogger.StartLogging(); DbInterception.Add(DatabaseLogger); } }
private void ConfigureLog() { if (LogConfig.DbLogger.IsActive) { DatabaseLogger.StartLogging(); DbInterception.Add(DatabaseLogger); } }
public AutoLotEntities() : base("name=AutoLotConnection") { DatabaseLogger.StartLogging(); DbInterception.Add(DatabaseLogger); //var context = (this as IObjectContextAdapter).ObjectContext; //context.ObjectMaterialized += OnObjectMaterialized; //context.SavingChanges += OnSavingChanges; }
public AutoLotEntities() : base("name=AutoLotConnection") { DbInterception.Add(new ConsoleWriterInterceptor()); DatabaseLogger.StartLogging(); DbInterception.Add(DatabaseLogger); var context = (this as IObjectContextAdapter).ObjectContext; context.ObjectMaterialized += Context_ObjectMaterialized; context.SavingChanges += Context_SavingChanges; }
public AutoLotEntities() : base("name=AutoLotConnection") { //DbInterception.Add(new ConsoleWriterlnterceptor()); DatabaseLogger.StartLogging(); DbInterception.Add(DatabaseLogger); // Код перехватчика. var context = (this as IObjectContextAdapter).ObjectContext; context.ObjectMaterialized += OnObjectMaterialized; context.SavingChanges += OnSavingChanges; }
public AutoLotDbContext() : base("name=AutoLotConnection") { DbInterception.Add(ConsoleWriterInterceptor); DatabseLogger.StartLogging(); DbInterception.Add(DatabseLogger); var context = (this as IObjectContextAdapter).ObjectContext; //just after properties of object is set and before object returned from context context.ObjectMaterialized += OnObjectMaterialized; //just after starting to push values to DB but before update DB context.SavingChanges += OnSavingChanges; }
public void DatabaseLogger_can_log_to_a_file() { Assert.Contains( "FROM [dbo].[Products]", CaptureFileOutput( f => { using (var logger = new DatabaseLogger(f)) { using (var context = new SimpleModelContext()) { logger.StartLogging(); context.Products.ToArray(); } } })); }
public void Dispose_stops_logging() { using (var context = new SimpleModelContext()) { var output = CaptureConsoleOutput( () => { using (var logger = new DatabaseLogger()) { logger.StartLogging(); context.Categories.ToArray(); } context.Products.ToArray(); }); Assert.Contains("FROM [dbo].[Categories]", output); Assert.DoesNotContain("FROM [dbo].[Products]", output); } }
public AutoLotEntities() : base("name=AutoLotConnection") { ////Register the Interception. //DbInterception.Add(new ConsoleWriterInterceptor()); //Use static DatabaseLogger field containing DatabaseLogger object, to invoking StartLogging(). DatabaseLogger.StartLogging(); //Register the DatabaseLogger. DbInterception.Add(DatabaseLogger); //Interceptor code var context = (this as IObjectContextAdapter).ObjectContext; context.ObjectMaterialized += OnObjectMaterialized; //SavingChanges fires after SaveChanges() is called(on the DbContext) but before the DB is updated. context.SavingChanges += OnSavingChanges; }
[Fact] // CodePlex 2568 public void DatabaseLogger_can_be_used_concurrently() { CaptureFileOutput( f => { using (var logger = new DatabaseLogger(f)) { logger.StartLogging(); ExecuteInParallel( () => { using (var context = new SimpleModelContext()) { for (var i = 0; i < 200; i++) { context.Products.AsNoTracking().Load(); } } }, 30); } }); }
protected override void Dispose(bool disposing) { logger.StartLogging(); DbInterception.Remove(logger); base.Dispose(disposing); }