Solution.Framework.Logger
8.0.0
dotnet add package Solution.Framework.Logger --version 8.0.0
NuGet\Install-Package Solution.Framework.Logger -Version 8.0.0
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="8.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Solution.Framework.Logger" Version="8.0.0" />Directory.Packages.props
<PackageReference Include="Solution.Framework.Logger" />Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Solution.Framework.Logger --version 8.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Solution.Framework.Logger, 8.0.0"
#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.
#:package Solution.Framework.Logger@8.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Solution.Framework.Logger&version=8.0.0Install as a Cake Addin
#tool nuget:?package=Solution.Framework.Logger&version=8.0.0Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Logger Nuget
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
- Email (only e-mail)
- EventLog (only Windows Event Log)
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": {
"MessageComplement": "Hml",
"FiltersFields": "senha,password,accesstoken,token",
"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",
"Source": "LoggerTest",
"WriteToConsole": true,
"ElasticLog": {
"Url": "",
"MinimumLevel": "Verbose"
},
"EmailLog": {
"SmtpServer": "",
"SmtpPort": 0,
"EnableSsl": false,
"From": "",
"To": "",
"Subject": "",
"MinimumLevel": "Verbose"
},
"MongoDBLog": {
"ConnectionString": "",
"DBTableName": "",
"DBAuditTableName": "",
"MinimumLevel": "Verbose"
},
"MSTeamsLog": {
"Webhook": "",
"MinimumLevel": "Verbose"
},
"SqlServerLog": {
"ConnectionString": "",
"DBTableName": "",
"DBAuditTableName": "",
"MinimumLevel": "Verbose"
},
"TextLog": {
"Path": "",
"MinimumLevel": "Verbose"
}
}
}
| Property | Required | Description |
|---|---|---|
| MessageComplement | No | Message complement for all logs |
| FiltersFields | No | Words to remove the value in a Json |
| OutputTemplate | No | Template configuration that goes at the beginning of logs to .log files |
| MinimumLevel | Yes | Indicates the minimum level that will be logged (Verbose, Debug, Information, Warning, Error, Fatal) |
| Source | No | Start name of .log files |
| WriteToConsole | Yes | Indicates that you will be logged into the application console |
ElascticLog (Object to log into Elasticsearch - no required)
| Property | Required | Description |
|---|---|---|
| Url | No | Elasticsearch URL |
| MinimumLevel | No | Indicates the minimum level that will be logged into ElasticSearch (Verbose, Debug, Information, Warning, Error, Fatal) |
EmailLog (Object to log into E-mail - no required)
| Property | Required | Description |
|---|---|---|
| SmtpServer | No | SMTP Server |
| SmtpPort | No | SMTP Port |
| EnableSsl | No | Enable or disable SSL |
| From | No | E-mail to "From" |
| To | No | E-mail to "To |
| Subject | No | E-mail subject |
| MinimumLevel | No | Indicates the minimum level that will be logged into E-mail (Verbose, Debug, Information, Warning, Error, Fatal) |
MongoDBLog (Object to log into MongoDB - no required)
| Property | Required | Description |
|---|---|---|
| ConnectionString | No | ConnectionString where is the table that will store the logs |
| DBTableName | No | Table name that will store the logs |
| DBAuditTableName | No | Audit table name, if exists, that will store the logs |
| MinimumLevel | No | Indicates the minimum level that will be logged into MongoDB (Verbose, Debug, Information, Warning, Error, Fatal) |
MSTeamsLog (Object to log into MS Teams - no required)
| Property | Required | Description |
|---|---|---|
| Webhook | No | URL to access MSTeams webhook |
| MinimumLevel | No | Indicates the minimum level that will be logged into MS Teams (Verbose, Debug, Information, Warning, Error, Fatal) |
SqlServerLog (Object to log into Sql Server - no required)
| Property | Required | Description |
|---|---|---|
| ConnectionString | No | ConnectionString where is the table that will store the logs |
| DBTableName | No | Table name that will store the logs |
| DBAuditTableName | No | Audit table name, if exists, that will store the logs |
| MinimumLevel | No | Indicates the minimum level that will be logged into Sql Server (Verbose, Debug, Information, Warning, Error, Fatal) |
TextLog (Object to log into text file - no required)
| Property | Required | Description |
|---|---|---|
| Path | No | Path where the .log files will be saved |
| MinimumLevel | No | Indicates the minimum level that will be logged into text file (Verbose, Debug, Information, Warning, Error, Fatal) |
When Log Type is "Audit", MongoDBLog or SqlServerLog required.
Syntax Logger
All methods have the same syntax, we'll show you with the Verbose and Error method
LoggerClass.Verbose("<message>", "<userName>", <logType>, "<event>", "<context>");
| Parameter | Required | Default Value | Description |
|---|---|---|---|
| message | Yes | Message that will be logged | |
| userName | No | Inform the user name that is generating the log | |
| logType | No | Application | Log type enumerator described above |
| event | No | null | string that will be logged in the Event field |
| context | No | null | string that will be logged in the Context field |
LoggerClass.Error("<message>", "<userName>", <logType>, <exception>, "<event>", "<context>");
| Parameter | Required | Default Value | Description |
|---|---|---|---|
| message | Yes | Message that will be logged | |
| userName | No | Inform the user name that is generating the log | |
| logType | No | Application | Log type enumerator described above |
| 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.Classes;
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, "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 EventLog
Method to write in Event Viewer (Application)
EventLogClass.Write("<message>", <eventLogEntryType>, <eventId>, <category>);
| Parameter | Required | Default Value | Description |
|---|---|---|---|
| message | Yes | message to write to event viewer | |
| eventLogEntryType | No | Information | message type |
| eventId | No | 0 | Event Id |
| category | No | 0 | Category |
Code Examples
using Solution.Framework.Logger.Classes;
class Program
{
static void Main(string[] args)
{
EventLogClass.Write("Message", EventLogEntryType.Information);
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Serilog.AspNetCore (>= 8.0.1)
- Serilog.Enrichers.Environment (>= 2.3.0)
- Serilog.Sinks.Elasticsearch (>= 9.0.3)
- Serilog.Sinks.Email (>= 2.4.0)
- Serilog.Sinks.EventLog (>= 3.1.0)
- Serilog.Sinks.MicrosoftTeams.Alternative (>= 1.4.3)
- Serilog.Sinks.MongoDB (>= 5.3.1)
- Serilog.Sinks.MSSqlServer (>= 6.5.1)
- Solution.Framework.Default (>= 8.0.0)
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 | 375 | 2/15/2024 |
| 7.0.9 | 414 | 11/15/2023 |
| 7.0.8 | 228 | 11/3/2023 |
| 7.0.7 | 374 | 9/16/2023 |
| 7.0.6 | 271 | 9/13/2023 |
| 7.0.5 | 259 | 9/8/2023 |
| 7.0.4 | 252 | 9/8/2023 |
| 7.0.3 | 260 | 9/8/2023 |
| 7.0.2 | 248 | 9/5/2023 |
| 7.0.1 | 534 | 1/19/2023 |
| 7.0.0 | 441 | 1/19/2023 |
| 6.0.3 | 768 | 8/9/2022 |
| 6.0.2 | 783 | 8/9/2022 |
| 6.0.1 | 1,073 | 7/29/2022 |
| 6.0.0 | 642 | 7/29/2022 |
| 5.0.3 | 2,365 | 9/11/2021 |
| 5.0.2 | 563 | 7/22/2021 |
| 5.0.1 | 630 | 7/8/2021 |
| 5.0.0 | 568 | 7/8/2021 |