Solution.Framework.Logger 5.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Solution.Framework.Logger --version 5.0.3                
NuGet\Install-Package Solution.Framework.Logger -Version 5.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="Solution.Framework.Logger" Version="5.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Solution.Framework.Logger --version 5.0.3                
#r "nuget: Solution.Framework.Logger, 5.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 Solution.Framework.Logger as a Cake Addin
#addin nuget:?package=Solution.Framework.Logger&version=5.0.3

// Install Solution.Framework.Logger as a Cake Tool
#tool nuget:?package=Solution.Framework.Logger&version=5.0.3                

Logger

Log framework.

Log Types

  • Application
  • Audit

The Audit log type will always be written to the database

Available Methods

  • Verbose
  • Debug
  • Information
  • Warning
  • Error
  • Fatal

Create table

	CREATE TABLE [Logs] (

	   [Id] bigint IDENTITY(1,1) NOT NULL,
	   [Message] nvarchar(max) NULL,
	   [MessageTemplate] nvarchar(max) NULL,
	   [Level] nvarchar(128) NULL,
	   [TimeStamp] datetime NOT NULL,
	   [Exception] nvarchar(max) NULL,
	   [Properties] nvarchar(max) NULL,
	   [Source] nvarchar(500) NULL,
	   [LogType] nvarchar(20) NULL,
	   [MachineName] nvarchar(500) NULL,
	   [EnvironmentUserName] nvarchar(500) NULL,
	   [UserNameLog] nvarchar(100) NULL,
	   [ContextName] nvarchar(max) NULL,
	   [EventName] nvarchar(500) NULL,
	   CONSTRAINT [PK_Logs] PRIMARY KEY CLUSTERED ([Id] ASC) 
	);

	CREATE INDEX IX1_Logs ON dbo.Logs ([Source],[TimeStamp]);

Settings for using Logger

Add the JSON below to appsettings.json

  "Logger": {
    "FiltersFields": "Senha,senha,Password,password",
    "Source": "LoggerTest",
    "Path": "C:\\Temp\\Log",
    "DBName": "Server=serverName; Database=dbName;Trusted_Connection=True;Application Name=Logger.Test;",
    "DBTableName": "tableName",
    "OutputTemplate": "[{Timestamp:dd/MM/yyyy HH:mm:ss} | {Level:u3}] [{LogType} | {MachineName} | {EnvironmentUserName} - {UserNameLog}] [{ContextName} | {EventName}]{NewLine}Message: {Message:lj}{NewLine}Error: {Exception}{NewLine}",
    "MinimumLevel": "Verbose",
    "WriteToConsole": true,
    "WriteToDB": true,
    "WriteToText": true
  }

Property|Required|Description FiltersFields|No|Words to remove the value in a Json Source|No|Start name of .log files Path|No|Path where the .log files will be saved DBName|No|ConnectionString where is the table that will store the logs DBTableName|No|Table name that will store the logs OutputTemplate|No|Template configuration that goes at the beginning of logs to .log files MinimumLevel|True|Indicates the minimum level that will be logged (Verbose, Debug, Information, Warning, Error, Fatal) WriteToConsole|True|Indicates that you will be logged into the application console WriteToDB|True|Indicates that it will be logged into a SQL Server database WriteToText|True|Indicates that it will be logged into a .log file

When Log Type is "Audit", MinimumLevel will always be considered as Verbose and WriteToDB will always be true.

Syntax Logger

All methods have the same syntax, we'll show you with the Verbose method

LoggerClass.Verbose("<message>", "<userName>");

Parameter|Required|Description message|True|Message that will be logged userName|No|Inform the user name that is generating the log

LoggerClass.Verbose("<message>", "<userName>", <logType>, <exception>, "<event>", "<context>");

Parameter|Required|Default Value|Description message|True||Message that will be logged logType|No|Application|Log type enumerator described above userName|No||Inform the user name that is generating the log exception|No|null|exception object event|No|null|string that will be logged in the Event field context|No|null|string that will be logged in the Context field

Code Examples

using Solution.Framework.Logger;
using Solution.Framework.Logger.Enums;
using Microsoft.Extensions.Configuration;

class Program
{
  static void Main(string[] args)
  {
    IConfiguration configuration = new ConfigurationBuilder()
      .AddJsonFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\") + "\\appsettings.json")
      .Build();

    LoggerClass.Configuration = configuration;
    LoggerClass.Source = null;

    LoggerClass.Verbose("Logger Test", Environment.UserName);
    LoggerClass.Verbose("Logger Test", Environment.UserName, LogTypeEnum.Application, null, "Event", "Context");
  }
}

Where configuration is an IConfiguration object from appsettings.config described above. The Source property is optional, if it is null, the framework will get the value of appsettings.config.

Syntax MessageDefault

Method to assemble the system-wide default message

MessageDefault.Error("<exception>", "<includeTargetSite>");

Parameter|Required|Default Value|Description exception|True||parameter with two data types, Exception or ModelError includeTargetSite|No|false|insert or not the Target Site information in the standard message

##Exemplos de código

using Solution.Framework.Logger;
using Solution.Framework.Logger.Enums;
using Microsoft.Extensions.Configuration;

class Program
{
  static void Main(string[] args)
  {
    try
    {

    }
    catch(Exception ex)
    {
        LoggerClass.Error("System error", LogTypeEnum.Application, Environment.UserName, MessageDefault.Error(ex), "Event", "Context");
    }
  }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Solution.Framework.Logger:

Package Downloads
Solution.Framework.Repository

Repository Framework

Solution.Framework.Http

Http Framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.0 119 2/15/2024
7.0.9 210 11/15/2023
7.0.8 111 11/3/2023
7.0.7 176 9/16/2023
7.0.6 138 9/13/2023
7.0.5 133 9/8/2023
7.0.4 125 9/8/2023
7.0.3 118 9/8/2023
7.0.2 121 9/5/2023
7.0.1 327 1/19/2023
7.0.0 263 1/19/2023
6.0.3 569 8/9/2022
6.0.2 550 8/9/2022
6.0.1 822 7/29/2022
6.0.0 442 7/29/2022
5.0.3 1,992 9/11/2021
5.0.2 349 7/22/2021
5.0.1 400 7/8/2021
5.0.0 355 7/8/2021