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

how to use nlog in MainActivity #31

Closed
vovanb opened this issue Jul 30, 2024 · 4 comments
Closed

how to use nlog in MainActivity #31

vovanb opened this issue Jul 30, 2024 · 4 comments
Labels
question Further information is requested

Comments

@vovanb
Copy link

vovanb commented Jul 30, 2024

Could you please explain how I get logger instance in Android MainActivity class?

@snakefoot
Copy link
Contributor

snakefoot commented Jul 30, 2024

Think the question is how to acquire Microsoft ILogger in MainActivity-class, since one is not allowed to override default constructor.

Think you will find more help on Google or StackOverflow.com or some support forum for MAUI development. This repository is mostly proof that MAUI-applications can integrate with NLog.

But maybe you can do this in the MainActivity-class (Just some random code found using Google):

var logger = (Application as IPlatformApplication).Services.GetService<ILogger<MainActivity>>();
logger.LogInformation("Hello from MainActivity");

Ofcourse you can always just create an NLog Logger like this (using the LogManager-singleton)

NLog.LogManager.GetCurrentClassLogger().Info("Hello from MainActivity");

@snakefoot snakefoot added the question Further information is requested label Jul 30, 2024
@vovanb
Copy link
Author

vovanb commented Jul 30, 2024

Thanks a lot for detailed answer. It is working. Do you know if possible to configure NLog.Targets.MauiLog to use ApplicationInsights in MAUI. I saw - example without NLog

@snakefoot
Copy link
Contributor

There is hangy.NLog.Targets.ApplicationInsights that allows NLog to integrate with ApplicationInsights using ConnectionString.

But if using Microsoft ILogger, then I guess one can also just have the NLog LoggingProvider living side-by-side with the standard ApplicationInsights-LoggingProvider by Microsoft.

@snakefoot
Copy link
Contributor

Closing due to inactivity.

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

No branches or pull requests

2 participants