企业库4.1日志记录错误?

时间:2011-11-11 18:11:01

标签: c# asp.net logging enterprise-library

我正在使用Enterprise library 4.1 logging。我在'EnterpriseLibraryContainer'收到编译错误。 EnterpriseLibraryContainer不适用于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);
    }
}

2 个答案:

答案 0 :(得分:0)

您是否有机会瞄准.NET 4 Client Profile而不是完整的.NET 4?

答案 1 :(得分: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();
}