Nodinite.Serilog.ApiSink
A Serilog sink that writes log events to Nodinite's Log API.
This project is built with .NET Standard 2.0.
Get Started
Install Nodinite.Serilog.ApiSink Nuget Package
Start by installing the NuGet package Nodinite.Serilog.Sink.Core.
Install-Package Nodinite.Serilog.ApiSink
Configuration
Nodinite requires some settings to be configured in order for events to be logged. Below you can see all settings that need to be configured.
Field | Example Value | Comment |
---|---|---|
LogAgentValueId | 503 | Who (Log Agents) sent the data |
EndPointName | "Nodinite.Serilog.ApiSink.Tests" | Name of Endpoint transport |
EndPointUri | "Nodinite.Serilog.Apisink.Tests.Serilog" | URI for Endpoint transport |
EndPointDirection | 0 | Direction for Endpoint transport |
EndPointTypeId | 0 | Type of Endpoint transport |
OriginalMessageTypeName | "Serilog.LogEvent" | Message Type Name |
ProcessingUser | "Nodinite" | Log Identity |
ProcessName | "My customer import process" | Name of process |
ProcessingMachineName | "localhost" | Name of server where log event originated |
ProcessingModuleName | "INT101-HelloHappyCustomers-Application" | Name of module |
ProcessingModuleType | "FileImport" | Type of module, exe, dll, service |
Using code
Besides Serilog, the following nuget packages need to be installed
Using the following code below you can start logging events to Nodinite.
var nodiniteApiUrl = "{Your Nodinite Log API Url";
var settings = new NodiniteLogEventSettings()
{
LogAgentValueId = 503,
EndPointDirection = 0,
EndPointTypeId = 0,
EndPointUri = "Nodinite.Serilog.ApiSink.Tests.Serilog",
EndPointName = "Nodinite.Serilog.ApiSink.Tests",
OriginalMessageTypeName = "Serilog.LogEvent",
ProcessingUser = "NODINITE",
ProcessName = "Nodinite.Serilog.ApiSink.Tests",
ProcessingMachineName = "NODINITE-DEV",
ProcessingModuleName = "DOTNETCORE.TESTS",
ProcessingModuleType = "DOTNETCORE.TESTPROJECT"
};
Logger log = new LoggerConfiguration()
.WriteTo.NodiniteApiSink(nodiniteApiUrl, settings)
.CreateLogger();
Using Appsettings.json (Preferred)
Besides Serilog, the following nuget packages need to be installed
- Microsoft.Extensions.Configuration
- Microsoft.Extensions.Configuration.Json
- Nodinite.Serilog.ApiSink
- Serilog.Settings.Configuration
Using the following code to initialize the logger in your application:
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
Logger log = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
And putting the following into your appsettings.json:
{
"Serilog": {
"Using": [ "Nodinite.Serilog.Apisink" ],
"WriteTo": [
{
"Name": "NodiniteApiSink",
"Args": {
"NodiniteApiUrl": "",
"Settings": {
"LogAgentValueId": 503,
"EndPointName": "Nodinite.Serilog.ApiSink.Tests",
"EndPointUri": "Nodinite.Serilog.ApiSink.Tests.Serilog",
"EndPointDirection": 0,
"EndPointTypeId": 0,
"OriginalMessageTypeName": "Serilog.LogEvent",
"ProcessingUser": "NODINITE",
"ProcessName": "Nodinite.Serilog.ApiSink.Tests",
"ProcessingMachineName": "NODINITE-DEV",
"ProcessingModuleName": "DOTNETCORE.TESTS",
"ProcessingModuleType": "DOTNETCORE.TESTPROJECT"
}
}
}
]
}
}
Logging Context Properties
ILogger log = new LoggerConfiguration()
.WriteTo.NodiniteApiSink(nodiniteApiUrl, settings)
.CreateLogger()
.ForContext("CorrelationId", Guid.NewGuid())
.ForContext("CustomerId", 12);
log.Information("Customer '12' has been imported.");
The Serilog sink will automatically loop over all context properties you have defined in your code and log them as part of your event to Nodinite.
Example: