[Yu Gong Series] September 2023 .NET CORE tool case-JMSFramework microservice framework (RemoteLog distributed log)


Preface

A distributed log is a system in which log messages can be distributed and replicated across multiple nodes. This enables high availability and fault tolerance, avoiding single points of failure and data loss.

In a distributed system, nodes need to coordinate and share information, and logs are one of the important ones. By recording communication between nodes, status changes and other information, troubleshooting and system debugging can be easily performed.

Common distributed log systems include Apache Kafka, Apache Flume, Log4j2, etc. These systems usually have the characteristics of high throughput, low latency, and high reliability, and are widely used in large-scale data processing, real-time monitoring, etc.

1. RemoteLog’s distributed log

1.Download and install RemoteLog

RemoteLog program download address: https://cccscls-my.sharepoint.com/:f:/g/personal/jack_mutc_ca/Et7VbP7sX31EiN-NQkPL0RgBL5RBG15_PyepR5Tx0PaqsQ?e=BTngox

Insert image description here
Download the RemoteLogServer compressed file corresponding to the operating system, decompress it, and run Jack.RemoteLog.WebApi.exe (windows) or Jack.RemoteLog.WebApi (linux)

Or install it with Docker

docker pull jackframework/jackremotelogwebapi:latest

2.Use

2.1 Installation package

Jack.RemoteLog

Insert image description here

2.2 Configuration

Add the following configuration to the appsettings.json file:

"Logging": {
    
    
  "ServerUrl": "http://127.0.0.1:9000",
  "ContextName": "YourContextName",
  "LogLevel": {
    
    
    "Default": "Debug"
  },
  "Console": {
    
    
    "LogLevel": {
    
    
      "Default": "Information"
    }
  }
}

Insert image description here
Register Jack.RemoteLog as the underlying log processing engine

#region 配置分布式日志
builder.Services.AddLogging(bud =>
{
    
    
    bud.AddConfiguration(builder.Configuration.GetSection("Logging"));
    bud.AddConsole();
    bud.UseJackRemoteLogger(builder.Configuration);
});
#endregion

If authentication is set on the RemoteLog server, the username and password need to be set here:

services.AddLogging(bud =>
{
    
    
    bud .AddConfiguration(builder.Configuration.GetSection("Logging"));
    bud .AddConsole();
    bud .UseJackRemoteLogger(builder.Configuration , new Options 
    {
    
    
           UserName = "",
           Password = ""
    });
});

2.3 Use

When an ILogger interface instance is used to log information, the information will be logged to the log server.

public class WeatherForecastController : ControllerBase
{
    
    
    private static readonly string[] Summaries = new[]
    {
    
    
    "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

    private readonly ILogger<WeatherForecastController> _logger;

    public WeatherForecastController(ILogger<WeatherForecastController> logger)
    {
    
    
        _logger = logger;
    }

    [HttpGet]
    public IEnumerable<WeatherForecast> Get()
    {
    
    
        _logger.LogInformation("我是RemoteLog的分布式日志");
        return Enumerable.Range(1, 5).Select(index => new WeatherForecast
        {
    
    
            Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
            TemperatureC = Random.Shared.Next(-20, 55),
            Summary = Summaries[Random.Shared.Next(Summaries.Length)]
        })
        .ToArray();
    }
}

Insert image description here

2.4 View logs

To view all logs on the server, you can open http://127.0.0.1:9000 through the browser, and you can easily obtain your program logs for monitoring and analysis.

Insert image description here

Guess you like

Origin blog.csdn.net/aa2528877987/article/details/132898870