Serilog.Sinks.LogBee
1.0.3
dotnet add package Serilog.Sinks.LogBee --version 1.0.3
NuGet\Install-Package Serilog.Sinks.LogBee -Version 1.0.3
<PackageReference Include="Serilog.Sinks.LogBee" Version="1.0.3" />
paket add Serilog.Sinks.LogBee --version 1.0.3
#r "nuget: Serilog.Sinks.LogBee, 1.0.3"
// Install Serilog.Sinks.LogBee as a Cake Addin #addin nuget:?package=Serilog.Sinks.LogBee&version=1.0.3 // Install Serilog.Sinks.LogBee as a Cake Tool #tool nuget:?package=Serilog.Sinks.LogBee&version=1.0.3
Serilog.Sinks.LogBee
A Serilog sink that writes events to logBee.net.
Basic usage
Log.Logger = new LoggerConfiguration()
.WriteTo.LogBee(new LogBeeApiKey("_OrganizationId_", "_ApplicationId_", "https://api.logbee.net"))
.CreateLogger();
try
{
Log.Information("Hello from {Name}!", "Serilog");
}
catch(Exception ex)
{
Log.Error(ex, "Unhandled exception");
}
finally
{
// send the events to logBee.net
Log.CloseAndFlush();
}
Advanced usage
logBee.net saves the log events under individual "Requests".
For console applications, a "Request" can be seen as an individual application execution.
Using a loggerContext
, you can configure the properties of the "Requests" generated by the different application executions.
using Serilog.Sinks.LogBee;
namespace Serilog.Sinks.LogBee_ConsoleApp;
class Program
{
static void Main(string[] args)
{
var loggerContext = new NonWebLoggerContext();
Log.Logger = new LoggerConfiguration()
.WriteTo.LogBee(
new LogBeeApiKey("_OrganizationId_", "_ApplicationId_", "https://api.logbee.net"),
loggerContext
)
.CreateLogger();
Foo(loggerContext);
Bar(loggerContext);
}
static void Foo(NonWebLoggerContext loggerContext)
{
loggerContext.Reset("http://application/foo");
Log.Information("Foo execution");
// send the logs to logBee.net
loggerContext.Flush();
}
static void Bar(NonWebLoggerContext loggerContext)
{
loggerContext.Reset("http://application/bar");
Log.Information("Bar execution");
// send the logs to logBee.net
loggerContext.Flush();
}
}
<table><tr><td> <img alt="foo/bar requests" src="https://github.com/logBee-net/serilog-sinks-logbee/assets/39127098/3344fce5-e196-477f-b7d0-e3eac54e065c" /> </td></tr></table>
Microsoft.Extensions.Logging
The Serilog.Sinks.LogBee
Sink works with the logging provider by the .NET Core.
To use the Microsoft.Extensions.Logging framework, you will also need to install the Serilog.Extensions.Hosting NuGet package.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog.Sinks.LogBee;
namespace Serilog.Sinks.LogBee_ConsoleApp;
class Program
{
static void Main(string[] args)
{
var loggerContext = new NonWebLoggerContext();
Log.Logger = new LoggerConfiguration()
.WriteTo.LogBee(
new LogBeeApiKey("_OrganizationId_", "_ApplicationId_", "https://api.logbee.net"),
loggerContext
)
.CreateLogger();
var services = new ServiceCollection();
services.AddLogging((builder) =>
{
builder.AddSerilog();
});
// we inject the loggerContext so we can access it later, if needed
services.AddSingleton(loggerContext);
var serviceProvider = services.BuildServiceProvider();
var logger = serviceProvider.GetRequiredService<ILogger<Program3>>();
logger.LogInformation("Hi there");
Log.CloseAndFlush();
}
}
"Request" properties
In console applications where the concept of requests may not apply directly, the NonWebLoggerContext
can be used to configure the "HTTP" properties that are saved in logBee.net.
Configuring the "Requests" can be useful for identifying and filtering different application executions in the logBee.net user-interface.
using Serilog.Sinks.LogBee;
namespace Serilog.Sinks.LogBee_ConsoleApp;
class Program
{
static async Task Main(string[] args)
{
var loggerContext = new NonWebLoggerContext();
Log.Logger = new LoggerConfiguration()
.WriteTo.LogBee(
new LogBeeApiKey("_OrganizationId_", "_ApplicationId_", "https://api.logbee.net"),
loggerContext
)
.CreateLogger();
int executionCount = 0;
while (true)
{
loggerContext.Reset(new RequestProperties($"http://application/execution/{executionCount}")
{
Headers = new Dictionary<string, string>
{
{ "key1", "value1" }
}
});
Log.Information("First log message from Serilog");
try
{
// execute some code
if (executionCount % 2 == 1)
throw new Exception("Oops, odd execution error");
}
catch (Exception ex)
{
Log.Error(ex, "Error executing some code");
// if we had an error, we set the "StatusCode" to 500
loggerContext.SetResponseProperties(new ResponseProperties(500));
}
finally
{
// flush the logs to the logBee endpoint
await loggerContext.FlushAsync();
}
await Task.Delay(5000);
executionCount++;
}
}
}
<table><tr><td> <img alt="Request properties" src="https://github.com/logBee-net/serilog-sinks-logbee/assets/39127098/2a9a5290-62ae-4365-bc6b-6552d7872f85" /> </td></tr></table>
Logging files
You can use the loggerContext
to save string content as files.
var loggerContext = new NonWebLoggerContext("/file-example");
Log.Logger = new LoggerConfiguration()
.WriteTo.LogBee(
new LogBeeApiKey("_OrganizationId_", "_ApplicationId_", "https://api.logbee.net"),
loggerContext
)
.CreateLogger();
Log.Information("Info message");
Log.Warning("War message");
loggerContext.LogAsFile(JsonSerializer.Serialize(new
{
eventCode = "AUTHORISATION",
amount = new
{
currency = "USD",
value = 12
}
}), "Event.json");
Log.CloseAndFlush();
<table><tr><td> <img alt="Request Files tab" src="https://github.com/logBee-net/serilog-sinks-logbee/assets/39127098/bbb278ff-b048-4aaf-b53f-74e34aeaf764" /> </td></tr></table>
<table><tr><td> <img alt="Request File preview" src="https://github.com/logBee-net/serilog-sinks-logbee/assets/39127098/58256b16-f4d4-4d09-b9cf-8ddd93d8eccd" /> </td></tr></table>
Examples
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Serilog (>= 3.1.1)
- System.Text.Json (>= 8.0.3)
-
net6.0
- Serilog (>= 3.1.1)
-
net8.0
- Serilog (>= 3.1.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Serilog.Sinks.LogBee:
Package | Downloads |
---|---|
Serilog.Sinks.LogBee.AspNetCore
Serilog sink that writes ASP.NET Core web app events to logBee.net |
GitHub repositories
This package is not used by any popular GitHub repositories.