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

Append: True not working and other questions #24

Closed
sebasijan opened this issue May 28, 2021 · 1 comment
Closed

Append: True not working and other questions #24

sebasijan opened this issue May 28, 2021 · 1 comment

Comments

@sebasijan
Copy link

sebasijan commented May 28, 2021

Adding the logger config as per documentation


  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Error"
    },
    "File": {
      "Path": "app.log",
      "Append": "True",
      "FileSizeLimitBytes": 3, // use to activate rolling file behaviour
      "MaxRollingFiles": 4     // use to specify max number of log files
    }
  }

And registering in my console app

var logFilePath = configuration.GetSection("Logging");

new ServiceCollection()
            .AddLogging(loggingBuilder => loggingBuilder.AddFile(logFilePath))

Then injecting to my class

public sealed class Application : IApplication
{
    private readonly IRORepository<Grv, int> _grvRORepository;
    private readonly ILogger<Application> _logger;

    public Application(
        IRORepository<Grv, int> grvRORepository,
        ILogger<Application> logger)
    {
        EnsureArg.IsNotNull(grvRORepository, nameof(grvRORepository));
        EnsureArg.IsNotNull(logger, nameof(logger));

        _grvRORepository = grvRORepository;
        _logger = logger;
    }

    public async Task RunAsync(CancellationToken cancellationToken)
    {
        _logger.LogInformation("hello there!");

        var grv = await _grvRORepository.GetByIdAsync(8, cancellationToken);

        _logger.LogError("YOU WOT M8");
    }
}

Generates 4 separate files:

app.log

2021-05-28T23:25:25.3186362+01:00	INFO	[Microsoft.EntityFrameworkCore.Infrastructure]	[Microsoft.EntityFrameworkCore.Infrastructure.ContextInitialized]	Entity Framework Core 3.1.15 initialized 'DomainContext' using provider 'EntityFrameworkCore.Jet' with options: DataAccessProviderFactory 

app1.log

2021-05-28T23:25:25.3284572+01:00	INFO	[Allways.Application.Application]	[0]	hello there!

app2.log

2021-05-28T23:25:25.7681790+01:00	INFO	[Microsoft.EntityFrameworkCore.Database.Command]	[Microsoft.EntityFrameworkCore.Database.Command.CommandExecuted]	Executed DbCommand (60ms) [Parameters=[@__id_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
SELECT TOP 1 `t`.`GRVNumber`, `t`.`GrvNumber`
FROM `TGRV` AS `t`
WHERE `t`.`GRVNumber` = @__id_0

app3.log

2021-05-28T23:25:25.8888947+01:00	FAIL	[Allways.Application.Application]	[0]	YOU WOT M8

These files are overwritten each time I run the application

Is that as expected? Shouldn't my "Append": "True" option cause them to not overwrite previous log files?

Also, how does the log level work, and how do I know what log is going to be written to which file?

The docs, while useful in registering the library, don't really explain how to use it properly

Really appreciate any guidance, thanks

@sebasijan
Copy link
Author

I seem to have misunderstood the meaning of this section in the config

  "FileSizeLimitBytes": 3, // use to activate rolling file behaviour
  "MaxRollingFiles": 4     // use to specify max number of log files

After setting both values to 0, it logs everything to a single file and appends it

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

1 participant