SoftlareStruct.Logger 1.0.3

dotnet add package SoftlareStruct.Logger --version 1.0.3                
NuGet\Install-Package SoftlareStruct.Logger -Version 1.0.3                
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.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SoftlareStruct.Logger --version 1.0.3                
#r "nuget: SoftlareStruct.Logger, 1.0.3"                
#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.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.

  1. Here is the package link in Nuget.org. https://www.nuget.org/packages/SoftlareStruct.Logger

  2. Install the package via Nuget Package Manager Console.

    Install-Package SoftlareStruct.Logger
    
  3. Add the following code to your Startup.cs file.

     public void ConfigureServices(IServiceCollection services)
     {           
         services.AddSoftlareLogger(Configuration);
     }
    
  4. 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();
    
  5. 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.

  1. 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();
        }
    }
    
  2. 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();
     	}
     }
    
  3. 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 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 105 6/14/2024
1.0.2 97 6/14/2024
1.0.1 90 6/13/2024
1.0.0 102 6/13/2024