J4JSoftware.Logging
4.1.1
See the version list below for details.
dotnet add package J4JSoftware.Logging --version 4.1.1
NuGet\Install-Package J4JSoftware.Logging -Version 4.1.1
<PackageReference Include="J4JSoftware.Logging" Version="4.1.1" />
paket add J4JSoftware.Logging --version 4.1.1
#r "nuget: J4JSoftware.Logging, 4.1.1"
// Install J4JSoftware.Logging as a Cake Addin #addin nuget:?package=J4JSoftware.Logging&version=4.1.1 // Install J4JSoftware.Logging as a Cake Tool #tool nuget:?package=J4JSoftware.Logging&version=4.1.1
J4JLogging
A Net 6.0 library which wraps Serilog's ILogger and extends it by reporting source code information.
Licensed under GNU GPL-v3.0.
See the github documentation for more detail.
TL;DR
Updated to Net 6.
using System;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using J4JSoftware.Logging;
using Microsoft.Extensions.Configuration;
using Serilog;
namespace ConfigurationBasedExample
{
// shows how to use J4JLogger with a configuration file
// see the ConfigurationBasedExample project for other files and details
class Program
{
static void Main(string[] args)
{
var loggerConfig = new J4JLoggerConfiguration();
var configRoot = new ConfigurationBuilder()
.AddJsonFile( Path.Combine( Environment.CurrentDirectory, "appConfig.json" ), true )
.Build();
loggerConfig.SerilogConfiguration
.ReadFrom
.Configuration( configRoot );
var logger = loggerConfig.CreateLogger();
logger.SetLoggedType(typeof(Program));
logger.Information("This is an Informational logging message");
logger.Fatal("This is a Fatal logging message");
}
}
}
The log file, log20210801.txt, looks like this:
2021-09-15 10:14:59.173 -07:00 [INF] This is an Informational logging message ConfigurationBasedExample.Program::Main (C:\Programming\J4JLogging\examples\ConfigurationBasedExample\Program.cs:32)
2021-09-15 10:14:59.238 -07:00 [FTL] This is a Fatal logging message ConfigurationBasedExample.Program::Main (C:\Programming\J4JLogging\examples\ConfigurationBasedExample\Program.cs:33)
Your log file's name will be different because, by default, the log file rolls daily and the last day logging took place will be embedded in the file name.
There is a simple way of trimming the logged source code file paths to make them relative to the project directory path. See the github documentation for how to do this.
Important Note
There is one important difference in how you call the logging methods from the Serilog standard.
If you pass nothing but simple strings to the methods as property values you must specify the types of the propertyValue arguments explicitly in the method call.
An example:
string someStringValue = "abcd";
_logger.Debug<string>("The value of that argument is {0}", someStringValue);
This requirement comes about because the memberName
, srcPath
and srcLine
arguments are automagically set for you by the compiler. The fact the memberName
and srcPath
arguments of the logging methods are strings makes them "collide" with string arguments you may specify. That makes explict type specifications for the arguments necessary when the compiler can't figure out what you mean...which is all too common 😃.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.Options (>= 6.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- Serilog (>= 2.10.0)
- Serilog.Expressions (>= 3.2.1)
- Serilog.Sinks.TextWriter (>= 2.1.0)
- System.Text.Json (>= 6.0.2)
NuGet packages (5)
Showing the top 5 NuGet packages that depend on J4JSoftware.Logging:
Package | Downloads |
---|---|
J4JSoftware.GeoProcessor
a library for processing GPX, KML and KMZ files, and snapping GPS tracks to roadways |
|
J4JSoftware.Logging.Twilio
Extends the J4JLogger library to support SMS logging via Twilio |
|
J4JSoftware.GeoProcessorApp
a console application for processing GPX, KML and KMZ files, and snapping GPS tracks to roadways |
|
J4JSoftware.GeoProcessorWPF
a WPF application for processing GPX, KML and KMZ files, and snapping GPS tracks to roadways |
|
J4JSoftware.WpFormsSurvey
utilities for exporting WPForms forms and survey responses to Excel (.xlsx) files |
GitHub repositories
This package is not used by any popular GitHub repositories.
changed how NetEventArg is created