ProphetsWay.Logger 1.1.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ProphetsWay.Logger --version 1.1.0
NuGet\Install-Package ProphetsWay.Logger -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ProphetsWay.Logger" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ProphetsWay.Logger --version 1.1.0
#r "nuget: ProphetsWay.Logger, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ProphetsWay.Logger as a Cake Addin
#addin nuget:?package=ProphetsWay.Logger&version=1.1.0

// Install ProphetsWay.Logger as a Cake Tool
#tool nuget:?package=ProphetsWay.Logger&version=1.1.0

ProphetsWay.Logger Build status

Logger is a quick to setup logging utility. It is designed so that you can establish the destinations for your log messages to one or many different outputs, each targeting different log level severities (so you can have a log of Errors and Warnings separate from a logger dumping Debug and Info statements).

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

You can pull a copy of the source code from GitHub, or you can reference the library from NuGet.org from within Visual Studio.

Install-Package ProphetsWay.Logger 
dotnet add package ProphetsWay.Logger 

Referencing and Using

Because this is the first utility of a handful, they will all exist in the namespace of "ProphetsWay.Utilities". Since the Logger is a static object, you can use it throughout your software to log messages without having to worry about any pre-configuration. However the point is to be able to create LoggerDestinations where ever you want, with a minimum specified LogLevel severity. You should establish your LoggerDestinations when your project initializes, so that the destinations are only created once.

using ProphetsWay.Utilities;

To create a simple Console Logging Destination, just instantiate a new "ConsoleDestination" class, and add it to the logger.

Logger.AddDestination(new ConsoleDestination());

or

var dest = new ConsoleDestination();
Logger.AddDestination(dest);

Destinations can be added and removed so long as you keep a reference to the object from when you initially added it. There is also the option to "Clear" all current destinations and simply add new ones.

Logger.RemoveDestination(dest);

and

Logger.ClearDestinations();

The built in destinations consist of ConsoleDestination, FileDestination, and EventDestination. There is also a base abstract class BaseLoggingDestination that anyone can use to inherit and implement their own custom destination.

ConsoleDestination will simply dump the log statement to your console, for both the console and file destinations, there is a text formatter that will append a timestamp and the log level to the message before it is rendered to the console.

Hello World!

is transformed into

3/15/2019 11:09:33 PM ::        Debug:  Hello World!

with the log level adding padding, so that scrolling thru the text will align timestamps, levels, and first characters of your message. Exceptions are also dumped into your logs as well.

3/15/2019 11:25:41 PM ::        Error:  Another generic message about an error occuring. (friendly message to show a UI maybe?)
This exception has an inner exception. (likely details to hide from a UI)

Inner Exception Message:
This is a specific Exception Message and will contain a stack trace.

A FileDestination requires a target filename to dump the logs into. If you want to clear the file on launch of your application (so that the file only contains logs from the 'last run') you can leave the reset flag as true, or if you want to have a running log, you can set it to false.

var fileDest = new FileDestination("Warnings.log", LogLevels.Warning, false);

A final additional parameter is available to specify the text Encoder to be used. The following are supported

  • ASCII
  • BigEndianUnicode
  • Unicode
  • UTF7
  • UTF8
  • UTF32

UTF8 is set by default.

The last destination available by default is the EventDestination. With this you will create the destination and then assign a delegate to the EventHandler. As a valid statement is logged, the event will trigger, and you can handle the message however you please. Generally this is the destination I use in my UI's. I will use Dispatcher to invoke the UI to render the log messages into a UI control for the user to see.

var evtDest = new EventDestination(LogLevels.Debug);
evtDest.LoggingEvent += (sender, eventArgs) => { /* whatever you want to do with the message here */ };

For simple actions in specific situations, the EventDestination is likely your best option. However if you have some specific functionality that you will use in a few different projects specific to your situation, you can also create your own personalized destinations. An example of a custom destination might be to create a specific database destination that is tightly coupled to a solution you are working in across multiple projects.

The BaseLoggingDestination requires an argument of LogLevel to be established, so any log statement with a severity of what was chosen or higher will be logged at that destination. The log levels are as follows:

  1. Debug
  2. Information
  3. Security
  4. Warning
  5. Error

If you set your destination to LogLevels.Debug, then all messages currently supported will be logged in your destination. If you choose LogLevels.Warning, then only Warning and Error logs will be logged in your destination.

You can have as many destinations as you wish; if you want to create two log files, one for Warnings and Errors, and a second one for all your Debug/Info logs, you only have to create two separate FileDestinations and add them both to the Logger.

var debugDest = new FileDestination("Debug.log", LogLevels.Debug);
var warnDest = new FileDestination("Warnings.log", LogLevels.Warning);
Logger.AddDestination(debugDest);
Logger.AddDestination(warnDest);

Running the tests

The library has 25 unit tests currently. I tried to cover everything possible. They are created with XUnit and utilize Moq for two tests. The Test project is included in this repository, as well as an Example project.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp1.0 is compatible.  netcoreapp1.1 is compatible.  netcoreapp2.0 is compatible.  netcoreapp2.1 is compatible.  netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 is compatible.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 is compatible.  net451 is compatible.  net452 is compatible.  net46 is compatible.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 is compatible.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 1.0

  • .NETCoreApp 1.1

  • .NETCoreApp 2.0

    • No dependencies.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETCoreApp 2.2

    • No dependencies.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETFramework 4.5.1

    • No dependencies.
  • .NETFramework 4.5.2

    • No dependencies.
  • .NETFramework 4.6

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETFramework 4.7.1

    • No dependencies.
  • .NETStandard 1.3

  • .NETStandard 1.6

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1-420.Beta 110 5/13/2022
3.0.1-420.Alpha 92 5/13/2022
3.0.1-418.Alpha 97 5/13/2022
3.0.1-352.Beta 89 4/27/2022
3.0.1-352.Alpha 85 4/27/2022
3.0.0 421 1/26/2021
3.0.0-248.Beta 127 1/26/2021
3.0.0-248.Alpha 120 1/26/2021
2.2.0-238.Alpha 145 1/26/2021
2.1.0 493 6/3/2020
2.1.0-182.Beta 216 6/3/2020
2.1.0-182.Alpha 207 6/3/2020
2.0.0 691 4/20/2019
2.0.0-105.Alpha 267 4/21/2019
2.0.0-97.Beta 265 4/20/2019
2.0.0-97.Alpha 273 4/20/2019
1.3.0 663 4/20/2019
1.3.0-95.Beta 270 4/20/2019
1.3.0-95.Alpha 259 4/20/2019
1.3.0-94.Alpha 275 4/20/2019
1.3.0-93.Alpha 270 4/20/2019
1.2.0 764 4/6/2019
1.2.0-Beta-89 423 4/6/2019
1.2.0-Beta-88 410 4/6/2019
1.2.0-Alpha-89 422 4/6/2019
1.2.0-Alpha-88 390 4/4/2019
1.2.0-Alpha-87 412 4/4/2019
1.1.0 555 3/24/2019
1.1.0-Beta-85 423 3/24/2019
1.1.0-Alpha-85 406 3/24/2019
1.1.0-Alpha-84 413 3/24/2019
1.1.0-Alpha-81 413 3/24/2019
1.1.0-Alpha-79 429 3/24/2019
1.1.0-Alpha-75 409 3/24/2019
1.1.0-Alpha-74 439 3/24/2019
1.1.0-Alpha-72 420 3/24/2019
1.0.0 556 3/16/2019
1.0.0-Alpha-51 412 3/16/2019
1.0.0-Alpha-50 399 3/16/2019
1.0.0-Alpha-49 419 3/16/2019
0.0.0-Alpha-48 424 3/16/2019
0.0.0-Alpha-46 438 3/16/2019
0.0.0-Alpha-43 424 3/7/2019
0.0.0-Alpha-42 433 3/6/2019
0.0.0-Alpha-41 435 3/6/2019
0.0.0-Alpha-36 427 3/4/2019
0.0.0-Alpha-34 396 3/4/2019
0.0.0-Alpha-32 440 3/2/2019
0.0.0-Alpha-30 427 3/2/2019
0.0.0-Alpha-28 434 3/2/2019