NealWalters
NealWalters

Reputation: 18197

Logging.Logger does not contain a definition for SetLogWriter

Copied code from here: https://www.c-sharpcorner.com/article/logging-block-in-microsoft-enterprise-library-6-0/

public class LoggerBlock
{
    protected LogWriter logWriter;
    public LoggerBlock()
    {
        InitLogging();
    }
    private void InitLogging()
    {
        logWriter = new LogWriterFactory().Create();
        Logger.SetLogWriter(logWriter, false);
    }
    public LogWriter LogWriter
    {
        get
        {
            return logWriter;
        }
    }
}

The compile error is:

Microsoft.Practies.EnterpriseLibrary.Logging.Logger does not contain a definition for 'SetLogWriter"

Sorry, I don't even know which version of the library I have installed. I'm trying to add some logging statements to an existing program that seems to have the app.config set up for Enterprise Library Logging.

Intellisense provides the following similar method only:

Logger.SetContextItemLog (object key, object value) 

Upvotes: 0

Views: 2099

Answers (1)

David Specht
David Specht

Reputation: 9074

I'm guessing you are using an older version that doesn't have the Logger.SetLogWriter() method. I just installed the latest version and the code you pasted works fine. Can you update the version you are using?

Edit: It looks like the Logger.SetLogWriter() method just sets the default Logger to use the LogWriter you just created. How about using the created LogWriter directly instead of the default Logger?

var logWriter = new LogWriterFactory().Create();
logWriter.Write("Message");

The following article might also give you some more information. Creating and Writing Log Entries

Upvotes: 1

Related Questions