CERINT.Logger


The class is implemented as a singleton. It is thread safe and optimized to not use locks. Due to the singleton implementation it saves memory when used. This allows you to use it all over your application without worrying about multiple class instantiations.

Supported Targets:

txtFile (YES)
xmlFile (YES)
jsonFile (YES
sqlDatabase (JSON/ XML / Relational)
mongoDatabase (YES)
windowsLog (YES)
rabbitMQ (YES)
email (YES)

After you have installed the package from nuget the first order of business is to edit the settings xml. We recommend you complete as many of the settings as possible. Even if you don’t intend to use all targets at first, it is nice to have the option. Contrary to other logs you can mix and match during runtime.

Settings file:

<level>100</level>

The min level of logs that will be processed. If the log level of the entry is lower than the number in the settings file it will not be logged. Ex. setting the value to 6 will log errors and above.

The existing levels are: 

  • trace =1,
  • debug =2,
  • info =4,
  • warning = 5,
  • error = 6,
  • exception =7,
  • critical = 8   

      

  • <txtFolderPath></txtFolderPath>
    • Where to store txt files.
  • <xmlFolderPath></xmlFolderPath>
    • Where to store xml files.
  • <jsonFolderPath></jsonFolderPath>
    • Where to store json files
  • <emailSMTPSettings>...</emailSMTPSettings>
    • All the required SMTP settings so that the log can be sent via email.
  • <mongoDBSettings>...</mongoDBSettings>
    • Contains 2 settings. One for the connection string and one for the DB name
  • <sqlDatabaseSettings>...</sqlDatabaseSettings>    
    • Contains the settings required to create a conncetions string. Additionally it has a <mode> setting that can be one of the following
      • Json (stores in json format in nvarcar max column)
      • XML (stores in XML format and column) 
      • Relational (creates full relationa structure based on object)

After you have configured the settings you can start using the logger. To log a message there are a number of functions available.

  1. bool Log(Enums.LogLevel level, Enums.Target target, object LogObject);
  2. bool Log(Enums.LogLevel level, Enums.Target target, string message);
  3. bool Log(Enums.LogLevel level, Enums.Target target, string message, Dictionary<int, string> parameters); 
  4. bool Log(Enums.LogLevel level, Enums.Target target, string message, Dictionary<string, string> parameters); 
  5. bool Log(Enums.Target target, Exception ex); 
  6. boolLog(Enums.Target target, string message, Exception ex);  

The properties to focus here are the level and target. As mentioned above you can mix and match. In the same function you can log the trace messages in a txt file and then in your catch block you can log an exception to a xml file or a database.

 

Change Log

Release(2019.12.1.1)
-- Fixed issue with log levels.

Release(2019.8.26.3)
--Added support for core 3.0 & Updated all used packages.

Release(2019.8.26.1)
--Added internal log funtionality.

Release(2019.8.25.2)
--Added fix to escape single ' from the sql insert for the exception object.
--Code Cleanup
--Update Packages

Release(2019.6.15.1-2)
--Code Cleanup 

Release(2019.6.9.3) 

--This is now V1 of the logger with the intended functionality complete.
--From now on release will be driven by user feedback, any bug reports and enhancement requests.

Release (2019.6.2.1)
--All targets are now supported for all functions. 

Release (2019.6.1.1)
--Support for logging to MS SQL (relational)

-- !! TWO MORE FUNCTIONs !! ->
bool LogToMSSQL(Enums.LogLevel level, string logMessage, Dictionary<int, string> parameters)
bool LogToMSSQL(Enums.LogLevel level, string logMessage, Dictionary<string, string> parameters)
[In this release the above function is implemented for the MS SQL target with the "relational" mode The rest of the function will me implemented as soon as possible.]

Release (2019.5.31.1)
--Support for logging to MS SQL (relational)
-- !! ONE MORE FUNCTION !! ->
bool Log(Enums.LogLevel level, Enums.Target target, string message)
[In this release the above function is implemented for the MS SQL target with the "relational" mode The rest of the function will me implemented as soon as possible.]

  Release (2019.5.27.1)
--Added Date as default column to the mssql relational logging option. 

  Release (2019.5.26.1)
--Support for logging to MS SQL (relational)
-- !! ONLY ONE FUNCTION !! ->
bool Log(Enums.LogLevel level, Enums.Target target, object LogObject);
[In this release the above function is implemented for the MS SQL target with the "relational" mode The rest of the function will me implemented as soon as possible.]

  Release (2019.5.25.1)
--More code refactoring to comply with the Sonar coding rules 
https://rules.sonarsource.com/csharp/ 

 Release (2019.5.24.1)
--Bug Fix some log entries were missing data as it was not passed to the output
--Code refactoring to comply with the Sonar coding rules
https://rules.sonarsource.com/csharp/

 Release (2019.5.19.1)
--Created partial classes to split code and improve maintenability

 Release (2019.5.18.3)
--Created partial classes to split code and improve maintenability

 Release (2019.5.18.1)
--Added support for storing messaged in MSSQL database in XML format.

 Release (2019.5.14.2)
--Added support for storing messaged in MSSQL database in JSON format. 

 Release (2019.5.05.3)
--Removed xml settings file and added a empty sample file.
--Added support for RabbitMq

 Release (2019.5.04.3)
--Release notes update. 

 Release (2019.5.04.2)
--Bug fixing for email subject. 

 Release (2019.5.04.1)
--Output to mongoDB is now supported. 

 Release (2019.4.28.2)
--Output to Email is now supported. 

 Release (2019.4.27.3)
--Output to Windows event log is now supported. 

 Release (2019.4.26.1)
--Output to Json file is now supported. 

 Release (2019.4.24.2)
--Bug Fix: xml files can be stored in their own location set in settings and not the same as txt files.

 Release (2019.4.22.2)
--Addition of generic function to log any given object.

Release (2019.4.21.2)
--Log to XML files is now available.

Release (2019.4.21.2)
--Log message to TXT file with extra parameters.
--Log xptn object to TXT file.