serilog-mssql / serilog-sinks-mssqlserver

A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
Apache License 2.0
278 stars 148 forks source link

[Question] ConnectionString in .NET Framework #397

Closed novelhawk closed 2 years ago

novelhawk commented 2 years ago

Bug Report / Support Request Template

Hello, I'm trying to port my .NET Core project's Serilog configuration to another project that targets .NET Framework. I was wondering if it was possible to load the connection strings from the project's XML configuration (from MSSql's XML or JSON configuration).

Ideally I would like to have the connection strings where they are and refer to them with their name.

I would be willing to port the complete XML project configuration to appsettings.json but it doesn't seem possible.

Code to load the configuration right now:

var configuration = new ConfigurationBuilder()
    .AddJsonFile("Config/Log.json")
    .Build();

Log.Logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

List the names and versions of all Serilog packages used in the project:

Target framework and operating system:

[ ] .NET Core 6 [ ] .NET Core 3.1 [ ] .NET Framework 4.8 [X] .NET Framework 4.7.x [ ] .NET Framework 4.6.x [ ] .NET Framework 4.5.x OS: Windows 10

ckadluba commented 2 years ago

Hi @novelhawk!

Sorry for the late reply. Loading SQL sink's connection strings and other settings from config sources is also possible for .NET Framwork. Please check out the documentation (https://github.com/serilog-mssql/serilog-sinks-mssqlserver#external-configuration-syntax) and the included samples for getting an idea how to do this.