NetLah.Extensions.Logging.Serilog
0.1.1
Prefix Reserved
See the version list below for details.
dotnet add package NetLah.Extensions.Logging.Serilog --version 0.1.1
NuGet\Install-Package NetLah.Extensions.Logging.Serilog -Version 0.1.1
<PackageReference Include="NetLah.Extensions.Logging.Serilog" Version="0.1.1" />
paket add NetLah.Extensions.Logging.Serilog --version 0.1.1
#r "nuget: NetLah.Extensions.Logging.Serilog, 0.1.1"
// Install NetLah.Extensions.Logging.Serilog as a Cake Addin #addin nuget:?package=NetLah.Extensions.Logging.Serilog&version=0.1.1 // Install NetLah.Extensions.Logging.Serilog as a Cake Tool #tool nuget:?package=NetLah.Extensions.Logging.Serilog&version=0.1.1
NetLah.Extensions.Logging.Serilog - .NET Library
NetLah.Extensions.Logging.Serilog is a library which contains a set of reusable utility classes for wrapping Serilog to Microsoft.Extensions.Logging.ILogger
and Serilog initialization as soon as the configuration available. The utility classes are AppLog
, AspNetCoreApplicationBuilderExtensions
, HostBuilderExtensions
.
Nuget package
Build Status
Getting started
Reference
ConsoleApp: https://github.com/serilog/serilog/wiki/Getting-Started#example-application
WebApp: https://github.com/serilog/serilog-aspnetcore#serilogaspnetcore---
Two-stage initialization: https://github.com/serilog/serilog-aspnetcore#two-stage-initialization
ConsoleApp
using NetLah.Extensions.Logging;
public static void Main(string[] args)
{
AppLog.InitLogger();
try
{
AppLog.Logger.LogInformation("Application configure..."); // write log console only
var configuration = ConfigurationBuilderBuilder.Create<Program>(args).Build();
var logger = AppLog.CreateAppLogger<Program>(configuration);
logger.LogInformation("Hello World!"); // write log to sinks
}
catch (Exception ex)
{
AppLog.Logger.LogCritical(ex, "Application terminated unexpectedly");
}
finally
{
Serilog.Log.CloseAndFlush();
}
}
ConsoleApp with dependency injection
using NetLah.Extensions.Logging;
public static async Task Main(string[] args)
{
AppLog.InitLogger();
try
{
AppLog.Logger.LogInformation("Application configure..."); // write log console only
var configuration = ConfigurationBuilderBuilder.Create<Program>(args).Build();
var logger = AppLog.CreateAppLogger<Program>(configuration);
logger.LogInformation("Service configure..."); // write log to sinks
IServiceCollection services = new ServiceCollection();
services.AddSingleton<IConfiguration>(configuration);
services.AddLogging();
services.AddSerilog();
services.AddScoped<Runner>();
await using var rootServiceProvider = services.BuildServiceProvider();
await using var scope = new AsyncDisposable<IServiceScope>(rootServiceProvider.CreateScope());
var runner = scope.Service.ServiceProvider.GetRequiredService<Runner>();
await runner.RunAsync().ConfigureAwait(false);
}
catch (Exception ex)
{
AppLog.Logger.LogCritical(ex, "Application terminated unexpectedly");
}
finally
{
Serilog.Log.CloseAndFlush();
}
}
private class AsyncDisposable<TService> : IAsyncDisposable where TService : IDisposable
{
public AsyncDisposable(TService service) => this.Service = service;
public TService Service { get; }
public ValueTask DisposeAsync()
{
if (Service is IAsyncDisposable asyncDisposable)
return asyncDisposable.DisposeAsync();
Service.Dispose();
return ValueTask.CompletedTask;
}
}
AspNetCore or Hosting application
using NetLah.Extensions.Logging;
public static void Main(string[] args)
{
AppLog.InitLogger();
try
{
AppLog.Logger.LogInformation("Application configure..."); // write log console only
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
AppLog.Logger.LogCritical(ex, "Host terminated unexpectedly");
}
finally
{
Serilog.Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog2(logger => logger.LogInformation("Application initializing...")) // write log to sinks
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
public class Startup
{
public Startup(IConfiguration configuration)
{
AppLog.Logger.LogInformation("Startup constructor"); // write log to sinks
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
var logger = AppLog.Logger;
logger.LogInformation("ConfigureServices..."); // write log to sinks
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
{
var logger1 = AppLog.Logger;
logger1.LogInformation("ConfigureApplication..."); // write log to sinks
logger.LogInformation("[Startup] ConfigureApplication..."); // write log to sinks
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "SampleWebApi v1"));
}
app.UseSerilogRequestLoggingLevel();
app.UseHttpsRedirection();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- NetLah.Abstractions (>= 0.1.0 && < 1.0.0)
- Serilog (>= 2.10.0 && < 3.0.0)
- Serilog.AspNetCore (>= 4.1.0 && < 5.0.0)
- Serilog.Extensions.Hosting (>= 4.1.2 && < 5.0.0)
- Serilog.Extensions.Logging (>= 3.0.1 && < 4.0.0)
- Serilog.Settings.Configuration (>= 3.1.0 && < 4.0.0)
- Serilog.Sinks.Console (>= 4.0.0 && < 5.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NetLah.Extensions.Logging.Serilog:
Package | Downloads |
---|---|
NetLah.Extensions.Logging.Serilog.AspNetCore
Initializing Serilog and wrapping Serilog to `Microsoft.Extensions.Logging.ILogger` for ASP.NETCore and WorkerService |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-rc3 | 123 | 11/15/2024 |
1.0.0-rc2 | 591 | 3/21/2024 |
1.0.0-rc1 | 306 | 1/12/2024 |
0.2.5 | 942 | 3/7/2023 |
0.2.4 | 1,340 | 1/2/2023 |
0.2.4-rc1 | 944 | 9/14/2022 |
0.2.3 | 1,216 | 9/2/2022 |
0.2.3-rc1 | 462 | 8/8/2022 |
0.2.3-alpha.0.1 | 251 | 7/7/2022 |
0.2.2 | 880 | 12/1/2021 |
0.2.1 | 695 | 11/19/2021 |
0.2.0 | 549 | 11/11/2021 |
0.2.0-rc2 | 35,880 | 10/18/2021 |
0.2.0-rc1.1 | 60,311 | 9/16/2021 |
0.1.1 | 82,819 | 7/27/2021 |
0.1.0 | 1,161 | 5/14/2021 |