Skip to content

Simple library to logging events in the .NET/.NET Core Framework applications.

License

Notifications You must be signed in to change notification settings

Spartanx10000/PlusLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlusLog

Simple library to logging events in the .NET/.NET Core Framework applications.

🔍 Features

  • This project is a .NET Standard 2.0 library built using Visual Studio 2017
  • Support both .NET Framework 4.5 > 4.x and .NET Core Framework 2.x
  • Allow events logging in multiple targets such file, database and mail
  • Use a single configuration file (pluslog.config) to set the information of the targets

📌 Target Applications

This library is aimed at .NET/.NET Core applications

🔧 Setup

  1. Add the reference to the project.

  2. Create the pluslog.config file.

    Note:

    In the case of desktop applications (Console / Winforms), create the pluslog.config file in the path where the application's .exe is located.

    In the case of web applications (ASP.NET), create the pluslog.config file in the root directory of the current application.

  3. Add the following structure:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
  <!--FileLogger settings-->
  <fileSettings> 
    <file name="Log.txt" path="C:\" />
  </fileSettings>
  <!--DbLogger settings-->
  <dbSettings>
    <connection name="Conn1" type="SQLSERVER" server="server" database="db" user="user1" password="test" />   
  </dbSettings>
  <!--MailLogger settings-->
  <mailSettings>
    <smtp host="smtp.gmail.com" enablessl="true" port="587" />
    <sender email="sender@gmail.com" password="pass" />
    <receiver email="receiver@gmail.com" />
  </mailSettings>
</configuration>

Note: In case you only need one of the targets, just add the settings section of that target in the file.

✏️ Usage

  • FileLogger
  1. Create a static variable to have access to the logger.
public static FileLogger log = LogHelper.GetFileLogger();
  1. Use the variable to create the events.
log.Debug("Test");
log.Success("Test");
log.Info("Test");
log.Warning("Test");
log.Error("Test");

PlusLog_File_Test

  • DbLogger
  1. Create a static variable to have access to the logger, specify the connection that the logger will use.
public static DbLogger log = LogHelper.GetDbLogger("Conn1");
  1. Use the variable to create the events.
log.Debug("Test");
log.Success("Test");
log.Info("Test");
log.Warning("Test");
log.Error("Test");

PlusLog_SQLServer_Test

Note: To use the DbLogger the following table must exist in the specified database:

CREATE TABLE dbo.LOG_t001(
        log_Id INTEGER IDENTITY(1,1),
        log_Event CHAR(10) NULL,
        log_Date DATETIME NULL,
        log_Message VARCHAR(250) NULL,
        PRIMARY KEY(log_Id));
  • MailLogger
  1. Create a static variable to have access to the logger.
public static MailLogger log = LogHelper.GetMailLogger();
  1. Use the variable to create the events.
log.Debug("MailLogger Test","Lorem Ipsum is simply dummy text....");
log.Success("MailLogger Test","Lorem Ipsum is simply dummy text....");
log.Info("MailLogger Test","Lorem Ipsum is simply dummy text....");
log.Warning("MailLogger Test","Lorem Ipsum is simply dummy text....");
log.Error("MailLogger Test","Lorem Ipsum is simply dummy text....");

PlusLog_Mail_Test

📝 License

This project is licensed under MIT License.