KSociety.Log.Srv.Behavior

K-Society Log is a centralized log system for .NET 6 and .NET 7 application


Keywords
k-society, ksociety, log, rabbitmq, logger, logging, serilog, serilog-sink
License
MS-RL
Install
Install-Package KSociety.Log.Srv.Behavior -Version 1.0.83

Documentation

Logo

build status NuGet GitHub all releases

KSociety.Log - Log System

Introduction

This is the README file for KSociety.Log. KSociety.Log is a .NET 6.0, .NET 7.0 and .NET 8.0 centralized log system, to work properly it needs RabbitMQ.

Examples

Here you can find several examples.

For Linux

Copy KSociety.Log.Srv.Host.service and KSociety.Log.Pre.Web.App.service files to /etc/systemd/system/ directory.

Port numbers

  • Log Server: 60500
  • Log Presenter: 61000

Get Packages

You can get KSociety.Log.Serilog.Sinks.RabbitMq by grabbing the latest NuGet package.

Get Started

If you work in localhost you will need to install the following applications:

In your project install KSociety.Log.Serilog.Sinks.RabbitMq nuget package. Remember to set the "Copy to Output Directory" option of the appsettings.json file to "Copy if newer".
Add the following section in the appsettings.json file of your application:

"Serilog": {
    "Using": [
      "KSociety.Log.Serilog.Sinks.RabbitMq"
    ],
    "MinimumLevel": {
      "Default": "Verbose",
      "Override": {
        "Microsoft": "Warning",
        "System": "Warning",
        "Grpc": "Error",
        "ProtoBuf": "Error"
      }
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "outputTemplate": "[{Timestamp:yyyy-mm-dd HH:mm:ss.fff} {Level:u3}] [{MachineName}] [{SourceContext}] {Message}{NewLine:1}{Exception:1}"
        }
      },
      {
        "Name": "RabbitMq",
        "Args": {
          "mqHostName": "localhost",
          "mqUserName": "KSociety",
          "mqPassword": "KSociety",
          "brokerName": "k-society_log",
          "exchangeType": "Direct",
          "exchangeDurable": false,
          "exchangeAutoDelete": true,
          "queueDurable": false,
          "queueExclusive": false,
          "queueAutoDelete": true,
          "batchPostingLimit": 50,
          "period": "00:00:02",
          "textFormatter": "KSociety.Log.Serilog.Sinks.RabbitMq.Sinks.RabbitMq.Output.LogEventFormatter, KSociety.Log.Serilog.Sinks.RabbitMq"
        }
      }
    ],
    "Enrich": [
      "FromLogContext",
      "WithMachineName",
      "WithProcessId",
      "WithThreadId"
    ],
    "Properties": {
      "ApplicationName": "your application name"
    }
  }

Add the following lines of code at the beginning of the main:

  KSociety.Log.Serilog.Sinks.RabbitMq.ProtoModel.Configuration.ProtoBufConfiguration();

  var configuration = new ConfigurationBuilder()
      .AddJsonFile("appsettings.json")
      .Build();

  global::Serilog.Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();

All log messages generated by your application will be sent to RabbitMQ and forwarded to the KSociety.Log.Srv.Host service.
KSociety.Log.Srv.Host service will:

  • forward the log messages to the web application KSociety.Log.Pre.Web.App for real-time viewing
  • write the log messages to a file

0. Installer

The installer.

GitHub Repository NuGet Download

1. Presentation

The presentation layer.

GitHub Repository NuGet Download

1.1 Presentation - Web

GitHub Repository NuGet Download
KSociety.Log.Pre.Web.App

2. Service

The service layer.

GitHub Repository NuGet Download
KSociety.Log.Srv.Agent NuGet NuGet
KSociety.Log.Srv.Behavior NuGet NuGet
KSociety.Log.Srv.Contract NuGet NuGet
KSociety.Log.Srv.Dto NuGet NuGet

2.1 Service - Host

GitHub Repository NuGet Download
KSociety.Log.Srv.Host

3. Application

The application layer.

GitHub Repository NuGet Download
KSociety.Log.App.Dto NuGet NuGet
KSociety.Log.App.ReqHdlr NuGet NuGet

4. Business

GitHub Repository NuGet Download
KSociety.Log.Biz NuGet NuGet
KSociety.Log.Biz.Event NuGet NuGet

Sink

GitHub Repository NuGet Download
KSociety.Log.Serilog.Sinks.Grpc NuGet NuGet
KSociety.Log.Serilog.Sinks.RabbitMq NuGet NuGet
KSociety.Log.Serilog.Sinks.SignalR NuGet NuGet

License

The project is under Microsoft Reciprocal License (MS-RL)

Dependencies

List of technologies, frameworks and libraries used for implementation: