DpConfig 1.0.1
dotnet add package DpConfig --version 1.0.1
NuGet\Install-Package DpConfig -Version 1.0.1
<PackageReference Include="DpConfig" Version="1.0.1" />
paket add DpConfig --version 1.0.1
#r "nuget: DpConfig, 1.0.1"
// Install DpConfig as a Cake Addin #addin nuget:?package=DpConfig&version=1.0.1 // Install DpConfig as a Cake Tool #tool nuget:?package=DpConfig&version=1.0.1
DpConfig - Sets up console configuration and logging
Namespace: DpUtilities
Nuget Package Name: DpConfig
Dependencies: DpUtilities, Serilog
Introduction
May be called at the head of a console application to create a configuration environment and (optionally) a Serilog logger. The configuration gives access to environment variables and to an appsettings.json file, if one exists at the application's root.
Optionally, a further Json settings file may be specified, which will be included if it exists.
If a logger is specified, the appsettings.json file, or the alternative settings file, must contain a valid Serilog
section.
The logger can be accessed by the global static instance Log
.
Constructor
public DpConfig (bool withLogging = true, settingsPath = null)
Both an appsettings.json file (if it exists) and a further specified json settings file (if specified and it exists) will be included.
Logging is assumed by default. Set withLogging
to false to set up configuration without logging.
Property
Property Config - Returns the configuration instance
public IConfigurationRoot Config { get; private set; }
Once the configuration has been constructed, a reference to it is available to the main program via this property.
Sample Serilog
section in appsettings.json
of alternative file
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft.EntityFrameworkCore.Database.Command": "Error",
"Microsoft.EntityFrameworkCore": "Error",
"Microsoft": "Warning",
"System": "Information"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "d:\\Temp\\LogTest.log",
"rollingInterval": "Day",
"retainedFileCountLimit": 31,
"outputTemplate": "{Timestamp:yy-MMM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
]
},
"TestSection": {
"TestString": "My Test String"
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Hosting (>= 8.0.0)
- Serilog (>= 3.1.1)
- Serilog.Settings.Configuration (>= 8.0.0)
- Serilog.Sinks.Console (>= 5.0.1)
- Serilog.Sinks.File (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Alternative settings file added and readme updated.