-1

I want to configure a log4net AdoNetAppender.

I tried to parameterize it with something like this in my log4net.config file :

<appender name="DatabaseAppender" type="log4net.Appender.AdoNetAppender">
        <bufferSize value="1" />
        <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <connectionString value="data source=MyServer;initial catalog=MyDataBase;integrated security=false;User ID=MyLogin;Password=MyPassword;Trust Server Certificate=True"/>
...

But when I run my app, if I set log4net.Internal.Debug to true, I get this error in the debug output

System.ArgumentException: Not supported keyword : 'trust server certificate'.

Of course, if I remove ";Trust Server Certificate=True" from the connection string, it doesn't work because my server refuses the connection. I tried to put the connection string in the app.config and reference it through the node instead of specify it in the log4net.config file but this is the same. I tested to use it in my code and there, it works.

Does anyone have an idea to either set the Trust Server Certificate to True for log4net, or use another way to make my connection working without specify it ?

Corabox
  • 157
  • 10
  • 2
    No spaces. `TrustServerCertifcate=True`, although this is not recommended for production environments. – squillman Jun 10 '22 at 17:46
  • @squillman called it correctly. FYI, all of the connection string keywords are defined at [SqlConnection.ConnectionString Property](https://learn.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring). – AlwaysLearning Jun 10 '22 at 22:13
  • @squillman, this was the clue, I'm going to post the answer. But why this should not be used in production environment ? What need to be done to avoid activate this parameter ? (the connectionString was already defined and nobody in the team can answer me why there was this parameter...) – Corabox Jun 13 '22 at 07:46

1 Answers1

0

As @squillman said, TrustServerCertifcate should not contains spaces. This was the origin of my problem.

We can notice that, surprisingly, System.Data.SqlClient.SqlConnection seems to accept it with spaces (that's why I did not understand why it worked when I tested it...)

Corabox
  • 157
  • 10