Last active
January 20, 2025 09:09
-
-
Save Calabonga/31a197429cf91b55e21746e74bd52ce7 to your computer and use it in GitHub Desktop.
Console Application Template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Samples; | |
public class AppSettings | |
{ | |
public string? Name { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Samples; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Serilog; | |
var configuration = new ConfigurationBuilder() | |
.AddJsonFile("appSettings.json", optional: true, reloadOnChange: true) | |
.Build(); | |
// logger from Serilog | |
var logger = new LoggerConfiguration().MinimumLevel.Verbose().WriteTo.Console().CreateLogger(); | |
// services | |
var services = new ServiceCollection(); | |
services.AddLogging(x => x.AddSerilog(logger)); | |
services.Configure<AppSettings>(x => { configuration.GetSection(nameof(AppSettings)).Bind(x); }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ItemGroup> | |
<PackageReference Include="Calabonga.DemoClasses" Version="2.0.0" /> | |
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.1" /> | |
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.1" /> | |
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.1" /> | |
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.1" /> | |
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.1" /> | |
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.1" /> | |
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="9.0.1" /> | |
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" /> | |
</ItemGroup> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment