Log4NetAdoNetAppender
Log4NetAdoNetAppender copied to clipboard
Cannot find ConnectionStringName
Hi,
.NET Core 6, when specifying connectionStringName in log4net, it cannot locate it. ConnectionStrings with connectionStringName is set in appsettings.json.
log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Could not open database connection []. Connection string context [Unable to resolve connection string from ConnectionString, ConnectionStrings, or AppSettings.].
System.InvalidOperationException: The ConnectionString property has not been initialized.
at Npgsql.NpgsqlConnection.Open(Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.Open()
at MicroKnights.Logging.AdoNetAppender.InitializeDatabaseConnection()
Nevermind, ConnectionStringFile value should be specified with {0}, which will be replaced.
I've researched the code and it uses ASPNETCORE_ENVIRONMENT/DOTNET_ENVIRONMENT variables in NetStandard and then searches for json file. I believe it should be more robust and always check for the file without environment name if connection string is missing in environment settings (e.g. check appsettings.json if appsettings.Development.json doesn't have connection string defined.