I have made my own HttpModule called 'JsonLogger' for logging json requests and responses.
For the logging I need a connectionstring.
To find the connectionstring, I added one in my web.config and I get it by code.
web.config
<connectionStrings>
<add name="WebShopConfiguration" connectionString="myConString"/>
</connectionStrings>
<system.web>
<httpModules>
<add name="JsonLogger" type="ServiceModel.Logging.JsonLogger, ServiceModel"/>
</httpModules>
</system.web>
<system.webServer>
<modules>
<add name="JsonLogger" type="ServiceModel.Logging.JsonLogger, ServiceModel"/>
</modules>
</system.webServer>
HttpModule
ConnectionString = System.Configuration.ConfigurationManager.
ConnectionStrings["WebShopConfiguration"].ConnectionString;
Everything works fine but imo this isn't clean (future developers won't know why that connectionstring is there in my web.config).
I would like to fill in the connectionstring where I add the httpmodule in my web.config. I tried this but this isn't working (like I already thought):
web.config
<add name="JsonLogger" type="ServiceModel.Logging.JsonLogger, ServiceModel" ConnectionString="myConString"/>
Property in HttpModule
[ConfigurationProperty("ConnectionString", DefaultValue = "", IsRequired = true, IsKey = false)]
public string ConnectionString { get; set; }
After some research I still don't find a way to do this. Anyone knows if what I'm trying to achieve is possible?
Many thanks, Kjell