Najlot.Log.Configuration.FileSource 4.0.3

dotnet add package Najlot.Log.Configuration.FileSource --version 4.0.3
                    
NuGet\Install-Package Najlot.Log.Configuration.FileSource -Version 4.0.3
                    
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="Najlot.Log.Configuration.FileSource" Version="4.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Najlot.Log.Configuration.FileSource" Version="4.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Najlot.Log.Configuration.FileSource" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Najlot.Log.Configuration.FileSource --version 4.0.3
                    
#r "nuget: Najlot.Log.Configuration.FileSource, 4.0.3"
                    
#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.
#addin nuget:?package=Najlot.Log.Configuration.FileSource&version=4.0.3
                    
Install Najlot.Log.Configuration.FileSource as a Cake Addin
#tool nuget:?package=Najlot.Log.Configuration.FileSource&version=4.0.3
                    
Install Najlot.Log.Configuration.FileSource as a Cake Tool

Najlot.Log

NuGet Version

</br>

Getting started:

You can start with just two lines of code:

var log = LogAdministrator.Instance.AddConsoleDestination().GetLogger(typeof(Program));
log.Info("Hello, World");

You can set the logging level on initialization and may change it later:

LogAdministrator.Instance
	.AddConsoleDestination(useColors: true)
	.SetLogLevel(LogLevel.Trace);

var log = LogAdministrator.Instance.GetLogger(typeof(Program));

log.Info("Hello, World!");

LogAdministrator.Instance.SetLogLevel(LogLevel.Warn);
log.Info("This message will not be logged.");

You tell the logger to log asynchronous (Putting the writing on an other thread):

LogAdministrator.Instance
    .SetCollectMiddleware<ConcurrentCollectMiddleware, FileDestination>()
    .SetCollectMiddleware<SyncCollectMiddleware, ConsoleDestination>()
    .AddConsoleDestination(useColors: true)
    .AddFileDestination("log.txt");

When you need something, then there is an example of a lot of things that are implemented:

LogConfigurationMapper.Instance.AddToMapping<ConsoleFormatMiddleware>();
LogConfigurationMapper.Instance.AddToMapping<DebugDestination>();

LogAdministrator.Instance
	// Using synchronous or asynchronous middleware to collect messages.
	// You can not use both. The last one called gets applied.
	//.SetCollectMiddleware<SyncCollectMiddleware, FileDestination>()
	.SetCollectMiddleware<ConcurrentCollectMiddleware, FileDestination>()

	// Tell the logger to write to a file and
	// calculate the file path it should write to.
	.AddFileDestination("{Year}-{Month}-{Day}.log")

	// Write to console using custom formatting and applying colors for different loglevel
	.AddMiddleware<ConsoleFormatMiddleware, ConsoleDestination>()
	.AddConsoleDestination(useColors: true)
				
	// Add a destination implemented below.
	.AddCustomDestination(new DebugDestination())

	// Read configuration from an XML file,
	// write an example file when not found,
	// listen for and apply changes to all loggers,
	// without restarting your application.
	.ReadConfigurationFromXmlFile("Najlot.Log.config",
		listenForChanges: true,
		writeExampleIfSourceDoesNotExists: true);

// Take specific logger.
var log = LogAdministrator.Instance.GetLogger(typeof(Program));

// Begin a scope of work
using (log.BeginScope("start up"))
{
	log.Trace("Beginning to start...");

	try
	{
		throw new Exception();
	}
	catch (Exception ex)
	{
		// Log a fatal error with the exception that caused the error.
		log.Fatal(ex, "Exception test: ");
	}
}

log.Info("Press any key.");
log.Flush();
Console.Read();

// Middleware used to format the output for console.
[LogConfigurationName(nameof(ConsoleFormatMiddleware))]
public sealed class ConsoleFormatMiddleware : IMiddleware
{
	public IMiddleware NextMiddleware { get; set; }

	public void Execute(IEnumerable<LogMessage> messages)
	{
		foreach (var message in messages)
		{
			message.Message = $"{message.DateTime} {LogArgumentsParser.InsertArguments(message.RawMessage, message.Arguments)} {message.Exception}";
		}

		NextMiddleware.Execute(messages);
	}

	public void Flush()
	{
	}

	public void Dispose()
	{
	}
}

// Custom destination that writes to System.Diagnostics.Debug.
[LogConfigurationName(nameof(DebugDestination))]
public sealed class DebugDestination : IDestination
{
	public void Log(IEnumerable<LogMessage> messages)
	{
		foreach (var message in messages)
		{
			System.Diagnostics.Debug.WriteLine(message.Message);
		}
	}

	public void Flush()
	{
	}

	public void Dispose()
	{
	}
}

Najlot.Log has a provider for Microsoft.Extensions.Logging:

using Microsoft.Extensions.Logging;
using Najlot.Log;
using Najlot.Log.Extensions.Logging;

...

var loggerFactory = new LoggerFactory();

loggerFactory.AddNajlotLog(administrator =>
{
	administrator
		.SetLogLevel(Najlot.Log.LogLevel.Info)
		.AddConsoleDestination(true)
		.AddFileDestination("log.txt");
});

var logger = loggerFactory.CreateLogger("default");
logger.LogInformation("Hello, World!");
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 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.

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
4.0.3 113 4/29/2025
4.0.2 151 4/21/2025
4.0.1 108 10/29/2024
4.0.0 121 10/11/2024
4.0.0-alpha-9 485 11/20/2020
4.0.0-alpha-8 441 11/20/2020
4.0.0-alpha-7 352 10/14/2020
4.0.0-alpha-6 444 5/30/2020
4.0.0-alpha-4 400 5/7/2020
4.0.0-alpha-2 454 5/7/2020
4.0.0-alpha-12 75 10/11/2024
4.0.0-alpha-11 342 6/27/2021
4.0.0-alpha-10 337 12/1/2020
4.0.0-alpha-1 404 5/6/2020
3.1.4 13,052 5/11/2020
3.1.3 602 12/2/2019
3.1.2 4,953 7/11/2019
3.1.1 712 6/23/2019
3.1.0 642 6/10/2019
3.0.1 667 6/2/2019
3.0.0 658 5/29/2019
2.1.1 696 5/3/2019
2.1.0 663 4/3/2019
2.0.1 687 3/30/2019
2.0.0 719 3/27/2019
1.0.11 810 11/8/2018
1.0.10 842 10/3/2018
1.0.9 11,069 10/1/2018