How to: Set Log Sink Levels (Code) (Velocity)

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Microsoft project code named "Velocity" offers the option to configure log sinks on both the client and server sides. On the client side, there are two options: configure log sinks in the application configuration file or configure them programmatically. The following procedures describe how to enable log sinks programmatically on the cache client.

On the server side, log sinks can only be configured in the cache host configuration file. For more information about these settings, see Log Sink Settings (Velocity).

To programmatically enable log sinks on the cache client, use the DataCacheFactory class static methods CreateLogSinks or EnableAllAvailableSinks. To disable log sinks programmatically, use the DisableLogSinks static method. For more information about log sink settings, see Log Sink Settings (Velocity).

Note

These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)

To create log sinks programmatically on the cache client

  1. Create a list of type DataCacheLogSink to contain the log sinks you want to enable.

  2. Create a DataCacheLogSink object for each log sink you want to enable.

    1. Specify the type of log sink you want by using the DataCacheSinkType enumeration in the sinkType parameter of the DataCacheLogSink constructor.

    2. Specify the trace level of the log sink by using the System.Diagnostics.TraceLevel enumeration in the logLevel parameter of the DataCacheLogSink constructor.

    3. (optional) If you are creating a file-based log sink, and you want to change the log file naming convention and storage location, define the log file naming convention with the sinkParam parameter of the DataCacheLogSink constructor. For more information about the file naming convention, see Log Sink Settings (Velocity).

  3. Add each log sink that you created to the list you created in the first step.

  4. Pass the list of log sinks to the sinkList parameter of the CreateLogSinks method to enable the log sinks on your cache client.

To enable all available log sinks programmatically on the cache client

  • Call the EnableAllAvailableSinks static method to enable the log sinks on your cache client.

To disable all log sinks programmatically on the cache client

  • Call the DisableLogSinks static method to enable the log sinks on your cache client.

Example

This example shows how to enable a console-based and a file-based log sink programmatically on the cache client. In this example, both log sinks are set to a Warning trace level. The file-based log sink sets the log file naming convention by using the sinkParam parameter.

'create a list for the desired log sinks
Dim sinklist As List(Of DataCacheLogSink)
sinklist = New List(Of DataCacheLogSink)(2)

'create file-based log sink, capture warnings and errors
Dim fileBasedSink As DataCacheLogSink
fileBasedSink = New DataCacheLogSink(DataCacheSinkType.FILE, _
                    TraceLevel.Warning, _
                    "DCache/dd-hh-mm")

'create console-based log sink, capture warnings and errors
Dim consoleBasedSink As DataCacheLogSink
consoleBasedSink = New DataCacheLogSink(DataCacheSinkType.CONSOLE, _
                    TraceLevel.Warning)

'add the log sinks to the sink list
sinklist.Add(fileBasedSink)
sinklist.Add(consoleBasedSink)

'enable the sinks
DataCacheFactory.CreateLogSinks(sinklist)
//create a list for the desired log sinks
List<DataCacheLogSink> sinklist = new List<DataCacheLogSink>(2);

//create file-based log sink, capture warnings and errors
DataCacheLogSink fileBasedSink = new DataCacheLogSink(DataCacheSinkType.FILE,
    TraceLevel.Warning, "DCache/dd-hh-mm");

//create console-based log sink, capture warnings and errors
DataCacheLogSink consoleBasedSink = new DataCacheLogSink(DataCacheSinkType.CONSOLE,
    TraceLevel.Warning);

//add the log sinks to the sink list
sinklist.Add(fileBasedSink);
sinklist.Add(consoleBasedSink);

//enable the sinks
DataCacheFactory.CreateLogSinks(sinklist);

This example shows how to enable all available log sinks programmatically on the cache client. This static method enables: console-based, file-based, and Event Tracing for Windows (ETW)-based log sinks. When the EnableAllAvailableSinks method is used, all these sinks are enabled and set to a trace level equal to Warning (1). The file-based sink uses the default file naming convention: DCacheTrace[$]/dd-hh (where $ is replaced by the Windows process identifier (PID), and dd-hh by the time format of "date-hour"). For more information about log sink settings and log file naming conventions, see Log Sink Settings (Velocity).

'enable all sinks, capture warnings and errors 
DataCacheFactory.EnableAllAvailableSinks()
//enable all sinks, capture warnings and errors 
DataCacheFactory.EnableAllAvailableSinks();

This example shows how to disable all log sinks programmatically on the cache client.

'disable all log sinks
DataCacheFactory.DisableLogSinks()
//disable all log sinks
DataCacheFactory.DisableLogSinks();

See Also

Tasks

How to: Get Started with a Simple Client (Code) (Velocity)
How to: Get Started with a Routing Client (Code) (Velocity)
How to: Enable Local Cache (Code) (Velocity)

Concepts

Log Sink Settings (Velocity)

Other Resources

Configuring the Cache Client with XML (Velocity)
Cache Concepts (Velocity)
Programming Guide (Velocity)