Click here to Skip to main content
15,867,308 members
Home / Discussions / Free Tools
   

Free Tools

This forum is for discussing and recommending Free tools for software development. Please post direct links to tools, and not just links to pages that review or list tools.No shareware and no commercial products allowed. Please report spammers by voting to remove their messages and reporting their accounts.

 
GeneralRe: Backup / Restore SQL Databases without the need of SMO Pin
Richard MacCutchan30-Oct-19 7:04
mveRichard MacCutchan30-Oct-19 7:04 
GeneralFree suite to handle video files Pin
phil.o28-Sep-19 22:33
professionalphil.o28-Sep-19 22:33 
GeneralFree NuGet Components Pin
MSBassSinger16-Jul-19 11:16
professionalMSBassSinger16-Jul-19 11:16 
GeneralRe: Free NuGet Components Pin
Richard MacCutchan16-Jul-19 21:26
mveRichard MacCutchan16-Jul-19 21:26 
GeneralRe: Free NuGet Components Pin
MSBassSinger17-Jul-19 1:11
professionalMSBassSinger17-Jul-19 1:11 
AnswerJHelpers README Contents Pin
MSBassSinger17-Jul-19 12:59
professionalMSBassSinger17-Jul-19 12:59 
GeneralRe: JHelpers README Contents Pin
Richard MacCutchan17-Jul-19 21:19
mveRichard MacCutchan17-Jul-19 21:19 
AnswerJLoggers README Content Pin
MSBassSinger17-Jul-19 13:34
professionalMSBassSinger17-Jul-19 13:34 
JLogger
=======

Overview
--------

JLogger is a singleton component as a .NET Standard 2.0 library component that
can be used with any .NET project, whether Core or Standard, on any supported OS
to access SQL Server.

JLogger has these characteristics:

- Multithreaded use – As a singleton, it is accessible from any thread, and
uses locking techniques to ensure there are no collisions.

- High throughput – if the log is being used by many threads concurrently, the
log writes do not stop the calling thread. JLogger uses a first-in,
first-out (FIFO) queue where log writes are put in a queue and written to a
file in a separate thread, concurrently in the background. The WriteDebugLog
command takes the parameters, creates the log data, puts it in a queue. None
of those steps are blocking.

- Send an Email – A debug log write can optionally send an email (SMTP
configuration data required)

- Multiple Log Entry Types – there are several log entry types to choose from.
What they each mean is up to the user writing the code. Some log types are
reserved for the component, and would be ignored in processing the log
entry. These are detailed below.

- New Log File each Day – after midnight, a new log file is created so log
files are named to show the date and time span the log was active.

- Log Retention – logs are automatically removed after the specified number of
days, unless zero is specified, in which case no log files are deleted.

- Tab-delimited Log File – the log is written as a tab-delimited file. This
enables opening up the file in programs like Excel for analysis.

LOG_TYPE Enum
-------------

The enum contains values for the types of logs, and for how the logs are created
and managed.

### LOG_TYPE Values for Logging

Unspecified - Used as a default value until an assignment is made.

Flow – Used to denote a log entry that can be used to trace program flow in the
log.

Error – Used to denote serious exceptions that generally require follow-up and
fixing.

Informational – Denotes the log entry is for information only.

Warning – Means the log entry is warning about a potentially serious condition.

System – Log entry relates to system data.

Performance – Log entry that usually shows elapsed time (as placed in the log
message by the coder) and/or start time.

Test – Used to indicate the log entry was intended for test results.

SendEmail – Used in the WriteDebugLog LOG_TYPE variable to specify that this log
entry should also send an email. The email is only sent if the same flag is used
in Log Management. Use of this flag here only applies to the specific log entry,
not the entire log.

Database - Log entry related to database operations

Service - Log entry related to service operations

Cloud - Log entry related to cloud operations

Management - Log entry related to management concerns or operations

Fatal - Log entry related to some fatal operation or state

Network - Log entry related to network issue or operation

Threat - Log entry related to a threat condition

### LOG_TYPE Values for Log Management

ShowModuleMethodAndLineNumber – Tells JLogger to include any available values
for what module name, method name, and line number the exception or log entry
was made. This is very useful for finding and correcting bugs in development,
quality assurance, and production code.

ShowTimeOnly - Shows time only, not date, in the debug log. Useful since debug
logs are closed and a new one created on the first write the next day after the
log file was opened. Do not use this flag if you want each log entry to show
date and time.

HideThreadID - Hides the thread ID from being printed in the debug log.

IncludeStackTrace – Writes the stack trace to the debug log. Otherwise, leaves
that column blank.

SendEmail – This is used if sending an email from a log entry that also uses
SendMail. The flag, when used in management (DebugLogOptions) enables sending
email if the log entry also calls for it by use of this flag. If this flag is
not set, the use of SendMail in a specific log entry is ignored, and no email is
sent. This allows globally turning email sends on and off by simply changing the
DebugLogOptions of the Logger instance.

IncludeExceptionData – This tells the JLogger instance to examine the Data
collection on all Exceptions, and log any name-value pairs it finds there. The
Exception.Data collection is often used in catch blocks to add real time values
to the exception before executing a “throw”. Use of the Data collection for this
saves much time in troubleshooting.

Example Code
------------

These lines of code are used to illustrate the use of JLogger. There are more
variations than documentation can show, but this shows a fully functioning use
of JLogger.

C#
// Usings

using Jeff.Jones.JLogger;
using Jeff.Jones.JHelpers;
// Setting a class-wide variable. What you set may
// be different for development, QA, production, and troubleshooting production.
// This global value for the program is usually stored in some
// configuration data location.

LOG_TYPE m_DebugLogOptions = LOG_TYPE.Error | LOG_TYPE.Informational |
         LOG_TYPE.ShowTimeOnly |
         LOG_TYPE.Warning |
         LOG_TYPE.HideThreadID |
         LOG_TYPE.ShowModuleMethodAndLineNumber |
         LOG_TYPE.System |
         LOG_TYPE.SendEmail;

// Setting variables used to configure the Logger
// Typically in the programs startup code, as early as possible.
Boolean response = false;
String filePath = CommonHelpers.CurDir + @"\";
String fileNamePrefix = "MyLog";
Int32 daysToRetainLogs = 30;

// Setting the Logger data so it knows how to build a log file, and
// how long to keep them. The initial debug log options is set here,
// and can be changed programmatically at anytime in the
// Logger.Instance.DebugLogOptions property.

response = Logger.Instance.SetLogData(filePath, fileNamePrefix, daysToRetainLogs, logOptions, "");

// These next lines may be omitted if not sending email from your log.
// Email setup.
Int32 smtpPort = 587;
Boolean useSSL = true;
List<String> sendToAddresses = new List<String>();
sendToAddresses.Add("MyBuddy@somewhere.net");
sendToAddresses.Add("John.Smith@anywhere.net");
response = Logger.Instance.SetEmailData("smtp.mymailserver.net", "logonEmailAddress@work.net",
                                        "logonEmailPassword", smtpPort, sendToAddresses,
                                        "emailFromAddress@work.net", emailReplyToAddress@work.net>",
                                        useSSL);

// End of email setup.

// This starts the log operation AFTER you have set the initial parameters.
response = Logger.Instance.StartLog();

// This ends the configuration example

// Example of use in a method
void SomeMethod()
{
  // Use of the Flow LOG_TYPE shows in the log when a method was entered,
  // and exited. Useful for debugging, QA, and development. The Flow bit
  // mask is usually turned off in production to reduce log size.
  if ((m_DebugLogOptions & LOG_TYPE.Flow) == LOG_EXCEPTION_TYPE.Flow)
    {
      Logger.Instance.WriteToDebugLog(LOG_TYPE.Flow, "1st line in method","");
    }

  // This variable notes when the method started.
  DateTime methodStart = DateTime.Now;

  try
    {
    // Do some work here
    // This is an example of logging used during
    // process flow. The bitmask used here does not
    // have to be "Informational", and may be turned
    // off in production.
    if ((m_DebugLogOptions & LOG_TYPE.Informational) == LOG_TYPE.Informational)
    {
        Logger.Instance.WriteToDebugLog(LOG_TYPE.Informational, 
                                        "Primary message", "Optional detail message");
    }

    // Do some more work
  }
  catch (Exception exUnhandled)
  {
    // Capture some runtime data that may be useful in debugging.
    exUnhandled.Data.Add("SomeName", "SomeValue");
    if ((m_DebugLogOptions & LOG_TYPE.Error) == LOG_TYPE.Error)
    {
       Logger.Instance.WriteToDebugLog(LOG_TYPE.Error, exUnhandled, "Optional detail message");
    }
  }
  finally
    {
      if ((m_DebugLogOptions & LOG_TYPE.Performance) == LOG_TYPE.Performance)
      {
        TimeSpan elapsedTime = DateTime.Now - methodStart;
        Logger.Instance.WriteToDebugLog(LOG_TYPE.Performance,
              String.Format("END; elapsed time = [{0:mm} mins, {0:ss} secs, {0:fff} msecs].",
              objElapsedTime));
      }

      // Capture the flow for exiting the method.

      if ((m_DebugLogOptions & LOG_TYPE.Flow) == LOG_EXCEPTION_TYPE.Flow)
      {
        Logger.Instance.WriteToDebugLog(LOG_TYPE.Flow, "Exiting method", "");
      }
} // END of method


Logger Methods and Properties
-----------------------------

### Static

C#
DEFAULT_DEBUG_LOG_OPTIONS
– constant with manufacturer recommend initial
settings. You do NOT have to use this and can build your own that resides in
your program.

C#
DEFAULT_LOG_RETENTION
– constant that is the default for how many days log files
are retained. You can use your own value and do NOT have to use this one.

C#
LOG_CACHE_FREQUENCY
– constant for how long between attempts to write the log
queue to the log file, in milliseconds.

### Instance

C#
DaysToRetainLogs
– (Get/Set) - How many days that the Logger instance retains
previous log files.

C#
DebugLogOptions
– (Get/Set) - The debug flags that are active during the
lifetime of the Logger instance

C#
Dispose()
– Implement the IDisposable.Dispose() method. Developers are supposed
to call this method when done with this Object. There is no guarantee when or if
the GC will call it, so the developer is responsible to. GC does NOT clean up
unmanaged resources, such as COM objects, so we have to clean those up, too.
There are no COM objects used in JLogger.

C#
EmailEnabled
– (Get ONLY) - True if sending email is enabled globally, false if
off globally. Email sending is set by the LOG_TYPE.SendMail bit being on or off
in DebugLogOptions,

C#
EmailLogonName
- (Get/Set) - The logon name expected by the SMTP email server.

C#
EmailPassword
- (Get/Set) - The logon password expected by the SMTP email
server.

C#
EmailServer
- (Get/Set) - The IP address or DNS name of the outgoing mail server

C#
FromAddress
- (Get/Set) - The email address to use with sending emails to
indicate who the email is from.

C#
IsDisposing
– (Get ONLY) - Tells the caller if this instance is already being
disposed. Returns true if the JLogger instance is being disposed, false if not.

C#
LogFileName
– (Get ONLY) - Fully qualified file name for the log file.

C#
LogPath
- (Get/Set) - Fully qualified path for the log file.

C#
ReplyToAddress
- (Get/Set) - The email address used to tell the recipient what
address to reply to.

C#
SendToAddresses
– (Get ONLY List<string>, but List<string> still supports
Add and other functionality. List<string> cannot be “set” as a List\<string\> object – internal creation only.) - These are the email addresses for log emails to be sent to.

C#
Boolean SetEmailData(String emailServer,  
                     String emailLogonName,  
                     String emailPassword,  
                     Int32 smtpPort,  
                     List<String> sendToAddresses,  
                     String fromAddress,  
                     String replyToAddress,
                     Boolean useSSL)
– Configure the email send functionality.

C#
Boolean SetLogData(String logPath,  
                   String logFileNamePrefix,  
                   Int32 daysToRetainLogs,  
                   LOG_TYPE debugLogOptions,  
                   String emergencyLogPrefixName = DEFAULT_EMERG_LOG_PREFIX)

Configures the Logger for logging before starting the log.

C#
SMTPPort
– (Get/Set) - The port that the SMTP email server listens on.

C#
Boolean StartLog()
– Once the Logger instance is configured, this is used to
start logging.

C#
Boolean StopLog()
– When the Logger instance is running, this is used to stop
logging.

C#
UseSSL
– (Get/Set) - True if the email server requires using SSL, false if not.

C#
Boolean WriteDebugLog(LOG_TYPE pExceptionType,  
                      Exception pExceptionToUse,  
                      String pOptionalLogMessage)
- Method used to write exception information to the log. This method writes a DebugLogItem instance to a queue, which is then emptied FIFO on a separate thread so calling this method does not block main thread activity.

C#
Boolean WriteDebugLog(LOG_TYPE pExceptionType,  
                      String message,  
                      String secondaryMessage = "")
- Method used to write message information to the log. This method writes a DebugLogItem instance to a queue, which is then emptied FIFO on a separate thread so calling this method does not block main thread activity.
AnswerJDAC README Contents Pin
MSBassSinger17-Jul-19 14:26
professionalMSBassSinger17-Jul-19 14:26 
GeneralVisual studio image library Pin
HumourStill10-Jul-19 18:38
HumourStill10-Jul-19 18:38 
GeneralRe: Visual studio image library Pin
Andreas Saurwein7-Jan-20 21:53
Andreas Saurwein7-Jan-20 21:53 
GeneralLooking for Recent Article on Backup Utility Pin
Patrick Skelton9-Jul-19 21:37
Patrick Skelton9-Jul-19 21:37 
GeneralRe: Looking for Recent Article on Backup Utility Pin
Simon_Whale14-Jul-19 21:56
Simon_Whale14-Jul-19 21:56 
GeneralRe: Looking for Recent Article on Backup Utility Pin
Patrick Skelton14-Jul-19 22:46
Patrick Skelton14-Jul-19 22:46 
GeneralRe: Looking for Recent Article on Backup Utility Pin
Simon_Whale14-Jul-19 22:48
Simon_Whale14-Jul-19 22:48 
GeneralRe: Looking for Recent Article on Backup Utility Pin
Nelek17-Jul-19 10:46
protectorNelek17-Jul-19 10:46 
GeneralRe: Looking for Recent Article on Backup Utility Pin
Patrick Skelton17-Jul-19 22:00
Patrick Skelton17-Jul-19 22:00 
NewsAsmSpy: Your Next Must-Have Tool If You Write in C#, VB, or F# Pin
David A. Gray2-Jul-19 5:00
David A. Gray2-Jul-19 5:00 
GeneralLooking for timer tool that works with TFS 2018 Pin
May16892-Jul-19 1:02
May16892-Jul-19 1:02 
QuestionRe: Looking for timer tool that works with TFS 2018 Pin
Maciej Los2-Jul-19 5:52
mveMaciej Los2-Jul-19 5:52 
AnswerRe: Looking for timer tool that works with TFS 2018 Pin
May16892-Jul-19 10:00
May16892-Jul-19 10:00 
GeneralStackblitz: do web dev in your browser, free Pin
raddevus24-Jun-19 4:27
mvaraddevus24-Jun-19 4:27 
GeneralRe: Stackblitz: do web dev in your browser, free Pin
Richard MacCutchan24-Jun-19 4:56
mveRichard MacCutchan24-Jun-19 4:56 
GeneralRe: Stackblitz: do web dev in your browser, free Pin
raddevus24-Jun-19 5:39
mvaraddevus24-Jun-19 5:39 
GeneralRe: Stackblitz: do web dev in your browser, free Pin
Richard MacCutchan24-Jun-19 5:48
mveRichard MacCutchan24-Jun-19 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.