Logging Configuration
This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.
The LoggingConfiguration class allows you to configure the event logging properties, such as specifying the log file name, controlling the amount of logging information to be generated, etc. The logging functionality can be configured in two ways:
- Configuring the Logging Functionality via Code
- Configuring the Logging Functionality via Config File
The LoggingConfiguration object is accessible through the Logging property that is exposed by the BackendConfiguration class.
public partial class EntitiesModel
{
static EntitiesModel()
{
BackendConfiguration.LoggingConfiguration loggingConfig = backend.Logging;
}
}
Partial Public Class EntitiesModel
Shared Sub New()
Dim loggingConfig As BackendConfiguration.LoggingConfiguration = backend.Logging
End Sub
End Class
The LoggingConfiguration class exposes the following properties:
-
LogEvents - specifies the amount of logging information to be generated. The event logging levels are as follows:
- None - logs no events.
- Errors - logs only serious errors (such as connections timing out). This is the default value.
- Normal - logs the most useful events that do not reduce performance significantly (e.g. SQL executed).
- Verbose - logs lots of events (this slows down the performance, could be used while debugging).
- All - logs all possible events (this slows down the performance very significantly, could be used while debugging).
- LogEventsToSysOut - controls if the log output is written to System.Console.
- LogEventsToTrace - controls if the logging information will be traced to a TraceListener or not.
- LogErrorsToWindowsEventLog - controls if errors are logged to the Windows Application Event Log.
- StackTrace - controls if the logging facilities append stack trace information. Enabling this setting may affect the performance of your application.
- EventStoreCapacity - controls the maximum number of log events stored in the ring buffer.
- MetricStoreCapacity - controls the capacity of the metric snapshot store.
- MetricStoreSnapshotInterval - controls the interval to perform metric snapshots in milliseconds.
-
Downloader- gets the DownloaderConfiguration object that allows you to configure the log downloader background thread. The DownloaderConfiguration class exposes the following properties:
- EventPollSeconds - controls the time in seconds between polls of the event ring buffer. The store interval for events is important. If the process generates more events than the configured buffer can store before the background process wakes up, the events are lost. By default, events are written in interval of 1 second.
- MetricPollSeconds - controls the time in seconds between polls of the metric snapshot ring buffer.
- Append - controls if the output is appended to an existing log file or if overwrite is performed.
- MaxFileSizeKB - specifies the max size of the log file in KB.
- NumberOfBackups - the number of old log files that Telerik Data Access keeps on the file system. After that number is exceeded, Telerik Data Access deletes the first log file before creating a new one. By default the maximum size of the log files is 1000KB and the maximum amount of historical files is 3. If the log file reaches the configured maximum size, it is renamed to fileName.1. If a file with name fileName.1 already exists, then it is renamed to fileName.2. If the maximum number of files has been reached, the oldest file is deleted. The new data will be stored in a new file.
- Filename - specifies the file name for the log output file.
- EventBinary - specifies if events should be logged in binary form.
- EventText - specifies if the logging information is written to a text file.
- MetricBinary - specifies if the metric snapshots are logged in binary form.
- DateFormat - controls the date time format to be used for event text.
Configuring the Logging Functionality via Code
To configure the logging functionality in the code, you need to extend your context class with another partial class with the same name and implement the CustomizeBackendConfiguration partial method. Using the config argument you can setup the Logging configuration for your context. For example:
public partial class EntitiesModel
{
static partial void CustomizeBackendConfiguration(ref BackendConfiguration config)
{
config.Logging.LogEvents = LoggingLevel.Normal;
config.Logging.LogEventsToSysOut = true;
config.Logging.LogEventsToTrace = false;
config.Logging.StackTrace = true;
config.Logging.EventStoreCapacity = 11000;
config.Logging.MetricStoreCapacity = 4600;
config.Logging.MetricStoreSnapshotInterval = 2000;
config.Logging.Downloader.EventPollSeconds = 2;
config.Logging.Downloader.MetricPollSeconds = 70;
config.Logging.Downloader.Append = true;
config.Logging.Downloader.MaxFileSizeKB = 2000;
config.Logging.Downloader.NumberOfBackups = 4;
config.Logging.Downloader.Filename = "DemoFile";
config.Logging.Downloader.EventBinary = true;
config.Logging.Downloader.EventText = true;
config.Logging.Downloader.MetricBinary = true;
}
}
Partial Public Class EntitiesModel
Private Shared Sub CustomizeBackendConfiguration(ByRef config As BackendConfiguration)
config.Logging.LogEvents = LoggingLevel.Normal
config.Logging.LogEventsToSysOut = True
config.Logging.LogEventsToTrace = False
config.Logging.StackTrace = True
config.Logging.EventStoreCapacity = 11000
config.Logging.MetricStoreCapacity = 4600
config.Logging.MetricStoreSnapshotInterval = 2000
config.Logging.Downloader.EventPollSeconds = 2
config.Logging.Downloader.MetricPollSeconds = 70
config.Logging.Downloader.Append = True
config.Logging.Downloader.MaxFileSizeKB = 2000
config.Logging.Downloader.NumberOfBackups = 4
config.Logging.Downloader.Filename = "DemoFile"
config.Logging.Downloader.EventBinary = True
config.Logging.Downloader.EventText = True
config.Logging.Downloader.MetricBinary = True
End Sub
End Class
Configuring the Logging Functionality via Config File
Another way to configure the logging functionality is to define the configuration in the App/web config file. For example:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="openAccessConfiguration"
type="Telerik.OpenAccess.Config.OpenAccessConfigSectionHandler, Telerik.OpenAccess"
requirePermission="false" />
</configSections>
<openAccessConfiguration>
<backendConfiguration name="LoggingConfiguration">
<logging logEvents="normal"
logEventsToSysOut="true"
logEventsToTrace="false"
stackTrace="true"
eventStoreCapacity="11000"
metricStoreCapacity="4600"
metricStoreSnapshotInterval="2000">
<downloader eventPollSeconds="2"
metricPollSeconds="70"
append="true"
maxFileSizeKB="2000"
numberOfBackups="4"
filename="DemoFile"
eventBinary="true"
eventText="true"
metricBinary="true"/>
</logging>
</backendConfiguration>
</openAccessConfiguration>
<connectionStrings>
</connectionStrings>
</configuration>
Again, you need to extend your context class with another partial class with the same name and add the following static constructor:
public partial class EntitiesModel
{
static EntitiesModel()
{
BackendConfiguration.MergeBackendConfigurationFromConfigFile(
backend,
ConfigurationMergeMode.ConfigFileDefinitionWins,
"LoggingConfiguration" );
}
}
Partial Public Class EntitiesModel
Shared Sub New()
BackendConfiguration.MergeBackendConfigurationFromConfigFile(backend,
ConfigurationMergeMode.ConfigFileDefinitionWins, "LoggingConfiguration")
End Sub
End Class
This will merge the settings from the config file to the backend static variable of the context class that holds the rest of the backend configuration.