RazorSoftware.Logging API

Simple, Lightweight and Portable .NET Library for Logging Messages to different outputs like Files, Consoles, and Debuggers.

Fully compatible with .NET Framework, .NET Core and .NET Standard.

Support for Windows Forms, WPF, CLI, and custom GUI Applications.

No extra dependencies required.

Fully documented.


Features

  • Automatic Console Window creation and management on GUI applications.
  • Handles multiple File Outputs simultaneously.
  • Per-Output message filtering via Log Levels.
  • Embedded Thread Synchronization compatible with multi App-Domain hosts.

Resources & Links

BitBucket Repository

Downloads

Online API Reference

NuGet Packages


Usage

Its recommended to use this library via the Nuget Packages available on the Downloads section of the GIT repository or by using the Nuget Package manager of your preferred IDE.

 

Initialization and Finalization code for the library is recommended to be included on the Main() method (Entry point) of the Application.

This single line of code is required for the library to perform its initialization with default outputs.

Log.Initialize();

After that, the logging library is fully initialized and messages can be written using any of the Write() and WriteLine() overloads for the Log static class. Example:

using com.RazorSoftware.Logging;

static void Main()
{
    // Pre-Initialization code
    ...

    // Initialize Library with default outputs
    Log.Initialize();

    // Force the creation of a new Console Window
    // Required for apps that dont normally have a console attached
    Log.Console.CreateConsole("My Debug Window");
    // Set the Console MinimumLogLevel
    Log.Console.MinimumLevel = LogLevel.Debug;
    // Enable the Console as an output
    Log.Console.Enabled = true;

    Log.Write("Hello ");
    Log.Write("World");
    Log.WriteLine("This is a Warning", LogLevel.Warning);
    Log.WriteLine("Max value for a byte variable is: %@", LogLevel.Message, byte.MaxValue);
    Log.WriteColoredLine("This is a line of text printed in red", ConsoleColor.Red);

    // Continue with your application logic
    // At this point the library is fully initialized and ready for logging with an active Console Window.
    ...
}

Log level can be modified using the MinimumLevel property on the desired output.
Log.Console.MinimumLevel = LogLevel.Error;

 

When the application is about to quit, the library needs to be shutdown in order to append statistical data, flush and close File outputs. This is done with a single call too.
Log.Shutdown();

Notices and Update logs

Scheduling scripts with CRON

A quick guide on setting up a cronjob to run a shell script at specific intervals or specific dates, with... read more

C# CircularBuffer

Efficient, Fast and Resizable Generic CircularBuffer implementation for C# with support for Forward and Backwards rotations read more

Gnu Screen

Useful cheat-sheet of Gnu Screen shortcuts and program arguments for terminal manipulation and multiplexing. read more

RazorSoftware.Logging-3134b41

v1.0.5.2-beta is live! Fixed FileOutput path handling on Linux/Osx platforms. FileOutput now translates paths across platforms by replacing backslashes with forward... read more

License

This software is protected under the GNU Lesser General Public License. http://www.gnu.org/licenses/

Copyright © 2020 RazorSoftware
Fabian R. contact@razorsoftware.dev
This file is part of RazorSoftware Logging Library.

RazorSoftware Logging Library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

RazorSoftware Logging Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with RazorSoftware Logging Library.  If not, see <http://www.gnu.org/licenses/>.

LGPLv3-Logo