2011-11-11 142 views
0

我正在使用企业库4.1日志记录。 'EnterpriseLibraryContainer'出现编译错误。 EnterpriseLibraryContainer不适用于4.1版本?企业库4.1日志记录错误?

public LogWriter defaultWriter; 

public Logging() 
{ 
    // Resolve the default LogWriter object from the container. 
    // The actual concrete type is determined by the configuration settings. 
    defaultWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>(); 
} 

[Description("Logging to EverViewer and RollingFile with Write method of a LogWriter")] 
public void LogWriter(string message, string title, EventLogEntryType eventType) 
{ 
    // Check if logging is enabled before creating log entries. 
    if (defaultWriter.IsLoggingEnabled()) 
    { 
     // Create a string array (or List<>) containing the categories. 
     string[] logCategories = new string[] { "General" }; 

     LogEntry logEntry = new LogEntry(); 
     logEntry.Message = message; 
     logEntry.Categories = logCategories; 
     logEntry.Priority = 10; 
     logEntry.EventId = 9005; 
     logEntry.Severity = ConvertEventType(eventType); 
     logEntry.Title = title; 
     defaultWriter.Write(logEntry); 
    } 
} 
+0

不能升级到5.0? – Amy

回答

0

EnterpriseLibraryContainer与Enterprise Library 5一起引入,因此不适用于Enterprise Library 4.1。

尝试用以下获取默认的作家替换代码:

public Logging() 
{ 
    // Resolve the default LogWriter object from the container. 
    // The actual concrete type is determined by the configuration settings. 
    defaultWriter = new LogWriterFactory().Create(); 
} 
0

你有没有机会瞄准.NET 4客户端配置文件而不是完整的.NET 4?

相关问题