SoftlareStruct.Logger
1.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package SoftlareStruct.Logger --version 1.0.2
NuGet\Install-Package SoftlareStruct.Logger -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SoftlareStruct.Logger" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SoftlareStruct.Logger --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SoftlareStruct.Logger, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SoftlareStruct.Logger as a Cake Addin #addin nuget:?package=SoftlareStruct.Logger&version=1.0.2 // Install SoftlareStruct.Logger as a Cake Tool #tool nuget:?package=SoftlareStruct.Logger&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
<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();
<p align="right">(<a href="#readme-top">back to top</a>)</p>
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
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.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.