nreco / logging

Generic file logger for .NET Core (FileLoggerProvider) with minimal dependencies
MIT License
296 stars 60 forks source link

Documentation #11

Closed hwjensen closed 2 years ago

hwjensen commented 4 years ago

Some documentation and an actual example would be nice.

VitaliyMF commented 4 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.

hwjensen commented 4 years ago

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

VitaliyMF commented 4 years ago

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)

hwjensen commented 4 years ago

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

VitaliyMF commented 4 years ago

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.

joepro commented 4 years ago

I am also having problems implementing this into my project. I have done the following, please tell me what I am missing

  1. I added all of your FileLoggerxx.cs files to my project
  2. in Startup.cs I added these lines using NReco.Logging.File; using Microsoft.Extensions.Logging;
  3. I added this code to the ConfigureServices function in Startup.cs services.AddLogging(loggingBuilder => { loggingBuilder.AddFile("app.log", append:true); });

When I try to compile I get the error that loggingBuilder does not contain a definition for AddFile.

What am I missing?

NicoKno commented 3 years ago

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.

Nom1fan commented 3 years ago

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!

VitaliyMF commented 3 years ago

@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).

sebasijan commented 3 years ago

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

sebasijan commented 3 years ago

I figured it out, needed to inject ILogger<ClassImInjectingItTo> instead

sebasijan commented 3 years ago

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?