Skip to content

oznakdn/EffectiveLogger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gleeman Effective Logger

SQLite

Install packages

dotnet CLI

dotnet add package Gleeman.EffectiveLogger --version 2.0.6
dotnet add package Gleeman.EffectiveLogger.SQLite --version 2.0.5

Program.cs

using Gleeman.EffectiveLogger.SQLite.Configurations;
builder.Services.AddSQLiteLog(options =>
{
    options.ConnectionString = "Connection string is here";
    options.WriteToFile = true;
    options.WriteToConsole = true;
    options.FilePath = "File path is here";
    options.FileName = "File name is here";
    options.MigrationAssembly = Assembly.GetExecutingAssembly();
});

MSSQLServer

Install packages

dotnet CLI

dotnet add package Gleeman.EffectiveLogger --version 2.0.6
dotnet add package Gleeman.EffectiveLogger.MSSqlServer --version 2.0.5

Program.cs

using Gleeman.EffectiveLogger.MSSqlServer.Configurations;
builder.Services.AddMSSqlServerLog(options =>
{
    options.ConnectionString = "Connection string is here";
    options.WriteToFile = true;
    options.WriteToConsole = true;
    options.FilePath = "File path is here";
    options.FileName = "File name is here";
    options.MigrationAssembly = Assembly.GetExecutingAssembly();
});

MySQL

Install packages

dotnet CLI

dotnet add package Gleeman.EffectiveLogger --version 2.0.6
dotnet add package Gleeman.EffectiveLogger.MySQL --version 2.0.5

Program.cs

using Gleeman.EffectiveLogger.MySQL.Configurations;
builder.Services.AddMySqlLog(options =>
{
    options.ConnectionString = "Connection string is here";
    options.WriteToFile = true;
    options.WriteToConsole = true;
    options.FilePath = "File path is here";
    options.FileName = "File name is here";
    options.MigrationAssembly = Assembly.GetExecutingAssembly();
});

PostgreSQL

Install packages

dotnet CLI

dotnet add package Gleeman.EffectiveLogger --version 2.0.6
dotnet add package Gleeman.EffectiveLogger.PostgreSQL --version 2.0.5

Program.cs

using Gleeman.EffectiveLogger.PostgreSQL.Configurations;
builder.Services.AddPostgreSqlLog(options =>
{
    options.ConnectionString = "Connection string is here";
    options.WriteToFile = true;
    options.WriteToConsole = true;
    options.FilePath = "File path is here";
    options.FileName = "File name is here";
    options.MigrationAssembly = Assembly.GetExecutingAssembly();
});

USAGE

public class LoggingMiddleware : IMiddleware
{
    private readonly IEffectiveLog<LoggingMiddleware> _log;

    public LoggingMiddleware(IEffectiveLog<LoggingMiddleware> log)
    {
        _log = log;
    }

    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        try
        {
            _log.Information($"{context.Request.Method} - {context.Request.Path} - {context.Response.StatusCode}");
            _log.Debug($"{context.Request.Method} - {context.Request.Path} - {context.Response.StatusCode}");
            _log.Fail($"{context.Request.Method} - {context.Request.Path} - {context.Response.StatusCode}");
            _log.Warning($"{context.Request.Method} - {context.Request.Path} - {context.Response.StatusCode}");

            await next.Invoke(context);
        }
        catch (Exception ex)
        {
           _log.Fail($"{context.Request.Method} - {context.Request.Path} - {context.Response.StatusCode} - {ex.Message}");
        }
    }
}

Console Screen

Console

File Screen

File

Database Screen

Database

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages