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