我正在尝试将使用Enterprise Library 5.0开发的一些代码迁移到6.0。以下代码给出了错误:类型或命名空间名称' LogWriterImpl'找不到(你错过了使用指令或程序集引用吗?)。显然这个类已被弃用。我想知道以下代码片段的等效调用是什么。
public static void Configure(string logLevel, string logFile, int logFileSize, bool addFileTraceListener, bool addConsoleTraceListener, bool addEventLogTraceListener)
{
lock (_lockObj)
{
_logFilePath = logFile;
_logLevel = logLevel;
_contextTrace = "";
_logSizeKB = logFileSize; //2MB default log file size
LogSource logSource = new LogSource("Empty");
IDictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
_formatter = (_logLevel == "DEBUG" || _logLevel == "ERROR") ?
new CustomTextFormatter("\n{timestamp(local)}\t {category}\n{message}\n") :
new CustomTextFormatter("{timestamp(local)} {shortcat} {message}");
IEnumerable<TraceListener> listeners = GetListeners(_logLevel, addFileTraceListener,
addConsoleTraceListener, addEventLogTraceListener);
logSource = new LogSource("MainLogSource", listeners, SourceLevels.All);
traceSources.Add("ERROR", logSource);
traceSources.Add("CRITICAL", logSource);
traceSources.Add("WARNING", logSource);
traceSources.Add("DEBUG", logSource);
traceSources.Add("INFO", logSource);
traceSources.Add("ACTIVITY", logSource);
//create the log writer
_writer = new LogWriterImpl(new ILogFilter[0], traceSources, new LogSource("Empty"), new LogSource("Empty"), logSource, "Error", false, true);
isConfigured = true;
}
}
答案 0 :(得分:1)
自己想出来。简单如下:
_writer = new LogWriter(new ILogFilter [0],traceSources,new LogSource(&#34; Empty&#34;),new LogSource(&#34; Empty&#34;),logSource,&#34; Error&# 34;,false,true);