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 | ||
KSociety.Log.Srv.Behavior | ||
KSociety.Log.Srv.Contract | ||
KSociety.Log.Srv.Dto |
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 | ||
KSociety.Log.App.ReqHdlr |
4. Business
GitHub Repository | NuGet | Download |
---|---|---|
KSociety.Log.Biz | ||
KSociety.Log.Biz.Event |
Sink
GitHub Repository | NuGet | Download |
---|---|---|
KSociety.Log.Serilog.Sinks.Grpc | ||
KSociety.Log.Serilog.Sinks.RabbitMq | ||
KSociety.Log.Serilog.Sinks.SignalR |
License
The project is under Microsoft Reciprocal License (MS-RL)
Dependencies
List of technologies, frameworks and libraries used for implementation:
- .NET 6 .NET 7(platform). Note for Visual Studio users: VS 2022 is required.
- Autofac (Inversion of Control Container)
- protobuf-net (protobuf-net is a contract based serializer for .NET code)
- RabbitMQ.Client (The RabbitMQ .NET client is an implementation of an AMQP 0-9-1 client library for C#)
- Serilog (structured logging)
- KSociety.Base.App.Shared ()
- KSociety.Base.EventBusRabbitMQ ()
- KSociety.Base.Srv.Agent ()
- KSociety.Base.Srv.Host.Shared ()