Ends in:
0 DAY
9 HRS
9 MIN
8 SEC
Ends in:
0 D
9 H
9 M
8 S
Open Closed

Set Serilog file retention for all MicroService #6821


User avatar
0
DominaTang created

How to setup Serilog file retention policy in Abp Framework for all Micro Services?

  • ABP Framework version: v7.2.1

6 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can install the serilog-sinks-rollingfile package and config it in the SerilogConfigurationHelper

    https://github.com/serilog/serilog-sinks-rollingfile/blob/dev/README.md

  • User Avatar
    0
    DominaTang created

    I noticed that Abp installed some Serilog packages, one thread in support forum did mentioned about SerilogConfigurationHelper, but couldn't find it in source code.

    My question is by modifying which place so that every AppService which has build in Logger property would have new SerigLog behavior. I believe the code below wouldn't change Logger's behavior. var log = new LoggerConfiguration() .WriteTo.RollingFile("log-{Date}.txt") .CreateLogger();

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    How to setup Serilog file retention policy in Abp Framework for all Micro Services?

    Are you using the Microservice template right?

    You can find it in the YourProjectName.Shared.Hosting project.

  • User Avatar
    0
    DominaTang created

    How to setup Serilog file retention policy in Abp Framework for all Micro Services?

    Are you using the Microservice template right?

    You can find it in the YourProjectName.Shared.Hosting project.

    That's the thing I feel weird. I noticed this file name in another thread. However, I check Shared.Hosting project there is no such file. I also checked the project template generated by Abp Suite last year, couldn't find this file neither. The ABP version is 7.1.0

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Could you share the Program code of the AdministrationService.HttpApi.Host project?

    You just need to find the logging configuration code, and change it.

    For example:

    logConfiguration.MinimumLevel.Information()
        .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
        .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
        .Enrich.FromLogContext()
        .Enrich.WithProperty("Application", $"{applicationName}")
        .WriteTo.Async(c => c.RollingFile("log-{Date}.txt")) // RollingFile
        .WriteTo.Elasticsearch(
            new ElasticsearchSinkOptions(new Uri(configuration["ElasticSearch:Url"]))
            {
                AutoRegisterTemplate = true,
                AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv8,
                IndexFormat = "MyProjectName-log-{0:yyyy.MM}"
            })
        .WriteTo.Async(c => c.Console());
    
    Log.Logger = logConfiguration.CreateLogger();
    

    https://github.com/serilog/serilog-sinks-rollingfile/blob/dev/README.md

  • User Avatar
    0
    DominaTang created

    Thanks, From that Host file I find code set up SerigLog and the extension method uses "SerilogConfigurationHelper" in Shared.Hosting.AspNetCore project

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19