Closed hwjensen closed 2 years ago
File logger usage is rather straightforward, code snippets are here ("How to use" section): https://github.com/nreco/logging
If you want to add an example I'm ok to accept your PR.
Thank you for getting back to me.
I would like to give you an example, unfortunately the code I have put together by guesswork does not work, so that would not not help anyone.
BTW: I do not know what a PR is?
KR Henrik
I would like to give you an example, unfortunately the code I have put together by guesswork does not work, so that would not not help anyone.
that's strange; file logging provider is added naturally with a single line of code:
services.AddLogging(loggingBuilder => {
loggingBuilder.AddFile("app.log", append:true);
});
BTW: I do not know what a PR is?
PR = Pull Request (means that you can create contribute by adding an example)
Oh yes, that use case works, but when try to specify parameters in the configuration file it stops working. This is why I think that documentation and examples would be a good thing, it would help me figure out what have done wrong.
OK, Thanks :-)
KR Henrik
but when try to specify parameters in the configuration file it stops working
That's strange, you can let me know your parameters if you need some help. Also you can check source code if something is not clear in the component.
I am also having problems implementing this into my project. I have done the following, please tell me what I am missing
When I try to compile I get the error that loggingBuilder does not contain a definition for AddFile.
What am I missing?
I think what you are missing is to add the NuGet package:
https://www.nuget.org/packages/NReco.Logging.File/
You are adding the cs files from the repo, but what you need is the correct package reference in your repo.
Is there a way to use this logger without dependency injection? I have a small project which does not use DI and I prefer to avoid adding it just for logging. Thanks in advance!
@Nom1fan sure, you can configure logging infrastructure by hands, simply by registering FileLoggerProvider
directly (see https://github.com/nreco/logging/blob/master/src/NReco.Logging.File/FileLoggerExtensions.cs).
Should I be able to inject something likeILogger
and call _logger.LogMessage("my custom message");
to be logged to a file? I don't see any example of how to do that
I figured it out, needed to inject ILogger<ClassImInjectingItTo>
instead
Its really unclear to me how this works though, it seems when I call my injected like _logger.LogInforman("hello")
it gets logged to a separate file to the normal application log? and if I try _logger.LogDebug
it does not get logged anywhere
Am I missing something really obvious, or it seems like the docs don't explain what is possible with this library?
Some documentation and an actual example would be nice.