Jason Z
Jason Z

Reputation: 21

What is the equivalent LogWriterImpl in Enterprise Library 6.0

I am trying to migrate some code we developed with Enterprise Library 5.0 to 6.0. Following code gave error: The type or namespace name 'LogWriterImpl' could not be found (are you missing a using directive or an assembly reference?). Apparently this class is deprecated. I am wondering what is the equivalent call to following code snippet.

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

Upvotes: 1

Views: 185

Answers (1)

Jason Z
Jason Z

Reputation: 21

Figured it out by myself. Simple as following:

_writer = new LogWriter(new ILogFilter[0], traceSources, new LogSource("Empty"), new LogSource("Empty"), logSource, "Error", false, true);

Upvotes: 1

Related Questions