SoftlareStruct.Logger
1.0.3
dotnet add package SoftlareStruct.Logger --version 1.0.3
NuGet\Install-Package SoftlareStruct.Logger -Version 1.0.3
<PackageReference Include="SoftlareStruct.Logger" Version="1.0.3" />
paket add SoftlareStruct.Logger --version 1.0.3
#r "nuget: SoftlareStruct.Logger, 1.0.3"
// Install SoftlareStruct.Logger as a Cake Addin #addin nuget:?package=SoftlareStruct.Logger&version=1.0.3 // Install SoftlareStruct.Logger as a Cake Tool #tool nuget:?package=SoftlareStruct.Logger&version=1.0.3
<a name="readme-top"></a>
About The Project
Getting Started
This package is a simple logger for your application. It is designed to be simple and easy to use. Espacially for SoftlareStruct projects.
Installation
Below you will find the installation instructions for the package.
Here is the package link in Nuget.org. https://www.nuget.org/packages/SoftlareStruct.Logger
Install the package via Nuget Package Manager Console.
Install-Package SoftlareStruct.Logger
Add the following code to your Startup.cs file.
public void ConfigureServices(IServiceCollection services) { services.AddSoftlareLogger(Configuration); }
Add the following code to your Program.cs file.
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .SoftlareConfiguration() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }) .UseSerilog();
If you want to keep RequestUserId in your logs, you should add the following code to your Configure method in Startup.cs file.
app.UseMiddleware<CatchUserIdMiddleware>();
Usage
There are two ways to use the logger. You can use it in your controllers or services.
- In your controller, you can use it like this. This way is recommended because it is include SourceContext.
public class HomeController : Controller { private readonly ILogger<HomeController> _logger; public HomeController(ILogger<HomeController> logger) { _logger = logger; } public IActionResult Index() { _logger.LogInformation("This is a log message."); return View(); } }
- You can use Static Log class wherever you want.
public class HomeController : Controller { public IActionResult Index() { Log.Information("This is a log message."); return View(); } }
- You should add the following code to your appsettings.json file. Or If you have different environment configuration files, you can seperate config however you want. Elastic Config is optional. If you want to use ElasticSearch, you should add Elastic Config.
"Softlare": { "Application": "[APPLICATIONNAME]", "Environment": "Production", "ElasticLogHost": { "Host": "http://localhost:9200/", "UserName": "[ELASTICUSERNAME]", "Password": "[ELASTICPASSWORD]" } }, "Serilog": { "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Information", "System": "Information", "Microsoft.AspNetCore": "Information", "Microsoft.EntityFrameworkCore": "Information", "Microsoft.EntityFrameworkCore.Database.Command": "Warning", "Microsoft.EntityFrameworkCore.Infrastructure": "Information", "Microsoft.EntityFrameworkCore.Query": "Information", "Microsoft.AspNetCore.Hosting": "Information", //RequestLoggingMiddleware "Microsoft.AspNetCore.Routing": "Warning", //RequestLoggingMiddleware "Microsoft.AspNetCore.Mvc": "Information", //RequestLoggingMiddleware "Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor": "Warning" //RequestLoggingMiddleware" } }, "WriteTo": [ { "Name": "Seq", "Args": { "serverUrl": "http://localhost:5341", "apiKey": "[APIKEY]" } }, { "Name": "File", "Args": { "path": "logs/log-.json", "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact", "rollingInterval": "Day", "rollOnFileSizeLimit": true, "fileSizeLimitBytes": 5242880, //5mb "retainedFileCountLimit": 7, "restrictedToMinimumLevel": "Warning" } } ] }
<p align="right">(<a href="#readme-top">back to top</a>)</p>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 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. |
-
net6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- Serilog.AspNetCore (>= 6.1.0)
- Serilog.Enrichers.ClientInfo (>= 2.0.3)
- Serilog.Enrichers.GlobalLogContext (>= 3.0.0)
- Serilog.Enrichers.RequestUserId (>= 1.0.0)
- Serilog.Sinks.Elasticsearch (>= 10.0.0)
- Serilog.Sinks.Seq (>= 7.0.1)
- SoftlareStruct.Info (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.