Search code examples
asp.net-mvclog4netlog4net-configuration

Log4Net Single Configuration File for Load Balancer


My question is how we can have a common Log4Net configuration in load balancer environment. Currently we are having configuration for each machine in load balancer and we have to copy the changes in all machine if we do any changes.

In order to be more scalable I am looking for a solution where we can a single log4net configuration for load balancer. I am sure log4net has some inbuilt capability to do the same but I am unable to find the solution.

For quick solution we are trying to copy the configuration in database and we will write the same in log4net.config file when application starts(first time only)

Help is required to have log4net configuration in more scalable way. Thanks in Advance

Following is the sample Log4Net.config file

< log4net> < root> < level value="DEBUG" /> < appender-ref ref="Log_New" /> < /root> < appender name="Log_New" 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="server=Server; uid=id; pwd=passweord; database=Log" /> < commandText value="ProcedureName" /> < CommandType value = "StoredProcedure" /> < parameter> < parameterName value="@SessionID" /> < dbType value="String" /> < size value ="200" /> < layout type="log4net.Layout.PatternLayout"> < conversionPattern value="%property{SessionID}" /> < /layout> < /parameter> < parameter> < parameterName value="@Event" /> < dbType value="String" /> < layout type="log4net.Layout.PatternLayout"> < conversionPattern value="%property{Event}" /> < /layout> < /parameter> < parameter> < parameterName value="@LogLevelKey" /> < dbType value="Int64" /> < layout type="log4net.Layout.PatternLayout"> < conversionPattern value="%property{LogLevelKey}" /> < /layout> < /parameter> < parameter> < parameterName value="@StackTrace" /> < dbType value="String" /> < size value ="-1" /> < layout type="log4net.Layout.PatternLayout"> < conversionPattern value="%property{StackTrace}" /> < /layout> < /parameter> < /appender> < /Log4Net>


Solution

  • If you're going to read the config from the database on startup, then there's not much point writing it to a file and then reading it in again, as there's an overload to load the configuration from a stream. There's also an overload to load the configuration from a URI, which might be a solution.