【问题标题】:Enterprise library 4.1 logging error?企业库 4.1 日志记录错误?
【发布时间】:2011-11-11 18:11:00
【问题描述】:

我正在使用 Enterprise library 4.1 日志记录。我在“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);
    }
}

【问题讨论】:

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


    【解决方案1】:

    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();
    }
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-19
        • 2010-09-26
        • 1970-01-01
        • 1970-01-01
        • 2011-02-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多