Skip to content

LogFactory-constructor with LoggingConfiguration-input-parameter is obsolete in NLog 5 #4782

@topsterde

Description

@topsterde

NLog version: 4.7.13 and 5.0.0-rc2

Platform: .NET 6

Current NLog config (xml or C#, if relevant)

This works with both NLog4 and NLog5:

var target = new FileTarget("logfile") { FileName = "log.txt" };
config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, target);
var logFactory = new LogFactory(config);

var logger = logFactory.GetCurrentClassLogger();
logger.Error("Test");

With NLog5 this LogFactory constructor is now obsolete.

If I change the code as suggested, then I get no more log output.

var config = new LoggingConfiguration(logFactory);
var target = new FileTarget("logfile") { FileName = "log.txt" };
config.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, target);

var logger = logFactory.GetCurrentClassLogger();
logger.Error("Test");

I have not found any information here:
https://nlog-project.org/2021/08/25/nlog-5-0-preview1-ready.html

How do I get this code with NLog5 to work?
I cannot use the static NLog.LogManager.Configuration, because I need multiple instances of the LogFactory for different use cases.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions