How to: Enable Tracing and Logging
Telerik Data Access enables you to trace and log statements generated by the OpenAccessContext. You can enable that feature with just a few code lines. The purpose of this tutorial is to show you how to perform that task.
In order to enable the Tracing and Logging:
- Open the file that holds your context class.
- Locate the GetBackendConfiguration method that provides the context constructor with an instance of the BackendConfiguration class.
-
The minimum additional settings you need to specify in it are:
backend.Logging.LogEvents = LoggingLevel.Normal; backend.Logging.MetricStoreSnapshotInterval = 0; backend.Logging.Downloader.Filename = "C:\\MyLog"; backend.Logging.Downloader.EventText = true;
backend.Logging.LogEvents = LoggingLevel.Normal backend.Logging.MetricStoreSnapshotInterval = 0 backend.Logging.Downloader.Filename = "C:\MyLog" backend.Logging.Downloader.EventText = True
Build and run your application.
-
In the following demonstration the LogLevel is set to Normal. A new instance of the model is created and all categories from the database are printed.
using (FluentModel dbContext = new FluentModel()) { foreach (Category category in dbContext.Categories) { Console.WriteLine(category.CategoryName); } }
Using dbContext As New FluentModel() For Each _category As Category In dbContext.Categories Console.WriteLine(_category.CategoryName) Next _category End Using
The content of the output log file should be similar to this:
Log File 20100729 12:33:49 PM pmf.start Log Level: all 20100729 12:33:49 PM driver.con.connect MultipleActiveResultSets=true;Pooling=false; Enlist=false;data source=.\SQLEXPRESS; initial catalog=Northwind; integrated security=True 20100729 12:33:49 PM driver.con.connect MultipleActiveResultSets=true;Pooling=false; Enlist=false;data source=.\SQLEXPRESS; initial catalog=Northwind; integrated security=True 20100729 12:33:49 PM driver.con.isolation 40327891 READ_COMMITTED(2) 20100729 12:33:49 PM driver.con.autoCommit 40327891 false 20100729 12:33:49 PM driver.pool.alloc active=1/10 idle=0/10 HP con=40327891 20100729 12:33:49 PM driver.con.rollback 40327891 20100729 12:33:49 PM driver.pool.release active=0/10 idle=1/10 con=40327891 20100729 12:33:49 PM pm.created