Home > OS >  Configure log4net connection string AdoNetAppender with "Trust server certificate=true"
Configure log4net connection string AdoNetAppender with "Trust server certificate=true"

Time:06-13

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 ?

CodePudding user response:

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...)

  • Related