Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use it in a windows service console application #121

Open
gitzko opened this issue Feb 25, 2022 · 1 comment
Open

Use it in a windows service console application #121

gitzko opened this issue Feb 25, 2022 · 1 comment

Comments

@gitzko
Copy link

gitzko commented Feb 25, 2022

Hi, I'm trying to figure out how to replace
ILog Logger = LogManager.GetLogger("Main");

with

ILoggerFactory loggerFactory = new LoggerFactory(
                            new[] { new Log4NetProvider((_, __) => true, true) }
                        );
            
            ILogger logger = loggerFactory.CreateLogger<Program>();

...but fail to provide the correct arguments.

Can anyone give a clue?

@huorswords
Copy link
Owner

Hello @gitzko,

Thanks by your question.

Are you using in any way the IServiceCollection extensions in your console application initialization?

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

var services = new ServiceCollection();
services.AddLogging(config => config.AddLog4Net());
var provider = services.BuildServiceProvider();

var logger = provider.GetRequiredService<ILogger<Program>>();

logger.LogInformation("Hello, World!");

If not, maybe you don't need to replace the initial call at all (or this adapter library), because Log4Net library still allows you to do it in that way (just add reference to Log4Net instead to Microsoft.Extensions.Logging.Log4Net.AspNetCore).

The objective of Microsoft.Extensions.Logging.Log4Net.AspNetCore library is to wire up the Log4Net logging with the Microsoft Logging framework, but if you are not going to use it... you know. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants