EasyLogFile

EasyLogFile

A .NET Standard library which help you easily work with log

Installation

https://www.nuget.org/packages/EasyPassword

Install-Package EasyLogFile

API

using EasyLogFile;

LoggerProvider

void LogInfo(string content);

Parameters image.png Example

string pathRootDirectory = Assembly.GetExecutingAssembly().Location.Replace("bin\\Debug\\netcoreapp3.1\\Test.dll", "Logs");
LoggerProvider loggerProvider = new LoggerProvider("pathRootDirectory");
loggerProvider.LogInfo("log normal");

void LogInfo(LogModel logModel);

Parameters image.png Example

loggerProvider.LogInfo(new LogModel {
                Message = "Message LogModel",
                Input = "Input Model",
                Output = "Output Model",
                MethodName = "method abc",
                TimeExecute = 123
            });

void LogError(Exception exception, string messageId = "");

Example

            try
            {
                string abc = null;
                abc.ToString();
            }
            catch (Exception ex)
            {
                loggerProvider.LogError(ex);
            }

string ReadLog(DateTime dateLog);

Example

string logText = loggerProvider.ReadLog(DateTime.Now);

Datalog as text image.png

LoggerJsonProvider

void WriteLog(LogJsonModel logJsonModel);

Parameters image.png Example

string pathRootDirectory = Assembly.GetExecutingAssembly().Location.Replace("bin\\Debug\\netcoreapp3.1\\Test.dll", "Logs");
            LoggerJsonProvider loggerJsonProvider = new LoggerJsonProvider(pathRootDirectory);

            //Info - Request
            loggerJsonProvider.WriteLog(new LogJsonModel
            {
                Timestamp = $"{DateTime.Now:dd/MM/yyyy HH:mm:ss}",
                LogLevel = LogLevel.INFO,
                TraceId = "ab-cderer-ueru",
                Method = "Request?.Method",
                Path = "Request?.Path.Value",
                Logger = Logger.REQUEST,
                MethodName = "Method ABCD",
                MetaData = new
                {
                    UserID = "Tester1"
                }
            });

            //Info-Response
            //Using IInvocation as AOP in netcore. To set it in middleware
            loggerJsonProvider.WriteLog(new LogJsonModel
            {
                Timestamp = $"{DateTime.Now:dd/MM/yyyy HH:mm:ss}",
                LogLevel = LogLevel.INFO,
                TraceId = "ab-cderer-ueru",
                Method = "Request?.Method",
                Path = "Request?.Path.Value",
                Logger = Logger.RESPONSE,
                MethodName = "Method ABCD",
                TimeExecute = 200 + " ms",
                Message = invocation.ReturnValue,
                MetaData = new
                {
                    UserID = "Tester1"
                }
            });

            //Error-Response
            //Using IInvocation as AOP in netcore. To set it in middleware
            try
            {
                string abc = null;
                abc.ToString();
            }
            catch (Exception ex)
            {
                loggerJsonProvider.WriteLog(new LogJsonModel
                {
                    Timestamp = $"{DateTime.Now:dd/MM/yyyy HH:mm:ss}",
                    LogLevel = LogLevel.ERROR,
                    TraceId = _httpContextAccessor.HttpContext.TraceIdentifier,
                    Method = _httpContextAccessor.HttpContext.Request?.Method,
                    Path = _httpContextAccessor.HttpContext.Request?.Path.Value,
                    Logger = Logger.RESPONSE,
                    MethodName = $"{invocation.TargetType.FullName}-{invocation.Method.Name}",
                    TimeExecute = 200 + " ms",
                    Message = ex,
                    MetaData = new
                    {
                        UserID = "Tester1"
                    }
                });
            }

List<LogJsonModel> ReadLog(DateTime? dateLog);

Example

List<LogJsonModel> readLogJson = loggerJsonProvider.ReadLog(DateTime.Now);

Datalog as text

image.png

Datalog as json image.png

**P/s: You can write similar javascript to read json log. Search client json object :D