Skip to content

Latest commit

 

History

History
95 lines (75 loc) · 3.8 KB

Readme.md

File metadata and controls

95 lines (75 loc) · 3.8 KB

NuGet

Veja a documentação em português clicando aqui.

LoggingHelper

Library for easy logging.


AVAILABLE FEATURES:

✔ Allows logging with different severity levels;
✔ Use the Write method to write logs;
✔ Customize log output format using FormatLogOutput;
✔ Use the LevelStack property to set the maximum level to be considered in the method stack;
✔ The LogValidity property allows setting the maximum time (in days) for the log file to be reset;
LogLevelFile represents the minimum log level to be recorded in the file;
✔ The LogPathFile property defines the location and file where the log should be recorded;
LogLevelConsole sets the minimum log level to be recorded on the console;
✔ Modify the Level enum to customize log levels;
✔ Set the log level using enumeration, number, or text;
✔ Use the CheckFile method to hide the log directory and perform validations;
GetCallingMethodName allows identifying the method that logged the message considering the stack level;
✔ Old log files can be automatically deleted through the check method (CheckFile);
✔ More features coming soon.



FEEDBACK:

https://bit.ly/FeedbackHappyHelper



INSTALLATION:

 dotnet add package LoggingHelper --version 1.2.0



EXAMPLE OF USE

Code:

using LH;

namespace App
{
    static class Program
    {
        static void Main()
        {
            try
            {
                // Optional
                //LoggingHelper.CheckFile(2,false);
                LoggingHelper.FormatLogOutput = "[<level>] <yyyy-MM-dd HH:mm:ss.fff> (<stack>) <message> | <obs>";
                //LoggingHelper.LevelStack = 3;
                //LoggingHelper.LogValidity = 2;

                //LoggingHelper.LogPathFile = @".\LOG_TEST\Logging_general.log";
                //LoggingHelper.LogLevelFile = 0;
                //LoggingHelper.LogLevelConsole = 0;

                LoggingHelper.Write("This is a trace log message.", 0, "Start application.");
                LoggingHelper.Write("Debug message.", 1, null);
                LoggingHelper.Write("This is a message for an information log [2].", 2, null);
                LoggingHelper.Write("This is also a message for an information log [3].", LoggingHelper.Level.INFO, null);
                LoggingHelper.Write("This is also a message for an information log [4].", "INFO", null);
                LoggingHelper.Write("This is also a message for an information log [5].", "2", null);

                throw new Exception();
            }
            catch (Exception ex)
            {
                LoggingHelper.Write("This is a log message for logging errors!", 4, ex.Message);
            }           
        }
    }
}

Result:

[TRACE] 2024-02-01 14:23:18.721 (/Main) This is a trace log message. | Start application.
[DEBUG] 2024-02-01 14:23:18.725 (/Main) Debug message.
[INFO] 2024-02-01 14:23:18.725 (/Main) This is a message for an information log [2].
[INFO] 2024-02-01 14:23:18.726 (/Main) This is also a message for an information log [3].
[INFO] 2024-02-01 14:23:18.727 (/Main) This is also a message for an information log [4].
[INFO] 2024-02-01 14:23:18.727 (/Main) This is also a message for an information log [5].
[ERROR] 2024-02-01 14:23:18.728 (/Main) This is a log message for logging errors! | Exception of type 'System.Exception' was thrown.