DpConfig 1.0.1

dotnet add package DpConfig --version 1.0.1
NuGet\Install-Package DpConfig -Version 1.0.1
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="DpConfig" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DpConfig --version 1.0.1
#r "nuget: DpConfig, 1.0.1"
#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 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 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. 
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
1.0.1 83 5/14/2024
1.0.0 74 5/14/2024

Alternative settings file added and readme updated.