Velocity提供了很详细的日志。缓存在群集中的生命周期和访问记录等都可以记录下来。
以下在代码中演示启用日志
using System; using System.Collections.Generic; using System.Linq; using System.Text; //添?加ó命ü名?空?间? using Microsoft.Data.Caching; using System.Diagnostics; namespace VolocityDemo { class Log { DataCacheFactory factory; public Log() { factory = new DataCacheFactory(); } ~Log() { //factory.Dispose(); } public void Test() { //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.Verbose, "DCache/yyyy-MM-dd"); //create console-based log sink, capture warnings and errors DataCacheLogSink consoleBasedSink = new DataCacheLogSink(DataCacheSinkType.CONSOLE, TraceLevel.Verbose); //add the log sinks to the sink list sinklist.Add(fileBasedSink); sinklist.Add(consoleBasedSink); //enable the sinks DataCacheFactory.CreateLogSinks(sinklist); } } }
开启日志后,在命令控制台上可以看到详细的日志(示例中将TraceLevel属性设为:Verbose,记录了所有日志)。
同时在应用程序的目录下可以看到记录的文本日志。本救命中的名称为:DCache2011-08-19.log