Configuring log4net with xml file
When you have log4net config in a separate config file you should not include the configuration and configSections elements. log4net should be the top level element after the xml declartion.
When you have log4net config in a separate config file you should not include the configuration and configSections elements. log4net should be the top level element after the xml declartion.
Try this (It should be OK!): <appender name=”LogFileAppender” type=”log4net.Appender.RollingFileAppender”> <file value=”logs\\” /> <appendToFile value=”true” /> <DatePattern value=”yyyy\\\\MM\\\\dd’.inf.log'” /> <rollingStyle value=”Date” /> <param name=”StaticLogFileName” value=”false” /> <layout type=”log4net.Layout.PatternLayout”> <header value=”[Header] ” /> <footer value=”[Footer] ” /> <conversionPattern value=”%date [%thread] %-5level %logger [%ndc] <%property{auth}> – %message%newline” /> </layout> </appender> It will create a logfile named ‘logs\2010\04\02.inf.log’ (let date be … Read more
You should be able to set the threshold property of each appender separately and include them in the same root. <appender name=”filelogAppender” type=”log4net.Appender.RollingFileAppender”> <threshold value=”Error” /> </appender> <appender name=”dblogAppender” type=”log4net.Appender.AdoNetAppender”> <threshold value=”Info” /> </appender> <root> <appender-ref ref=”filelogAppender” /> <appender-ref ref=”dblogAppender” /> </root> reference
Do you call log4net.Config.XmlConfigurator.Configure(); somewhere to make log4net read your configuration? E.g. in Global.asax: void Application_Start(object sender, EventArgs e) { // Code that runs on application startup // Initialize log4net. log4net.Config.XmlConfigurator.Configure(); }
You can enable log4net internal debugging by adding the key log4net.Internal.Debug to your application configuration file. <appSettings> <add key=”log4net.Internal.Debug” value=”true”/> </appSettings> This will write debug messages to the console and the System.Diagnostics.Trace system. You can then log these messages to a text file by adding a trace listener to you configuration file. Make sure the … Read more
1) Modify the command text: INSERT INTO Log4Net ([Date],[Thread],[Level],[Logger],[Message],[Exception],[MyColumn]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception, @CustomColumn) 2) Add the parameter definition for the custom column: <parameter> <parameterName value=”@CustomColumn”/> <dbType value=”String” /> <size value=”255″ /> <layout type=”log4net.Layout.PatternLayout”> <conversionPattern value=”%property{CustomColumn}” /> </layout> </parameter> 3) Then use one of log4net’s contexts to transfer values to the parameter: … Read more
You are doing this the hard way! Define your log4net config as XML in your application’s configuration file and use %property{} to advantage: <appender name=”YourAppender” type=”log4net.Appender.RollingFileAppender”> <file type=”log4net.Util.PatternString” value=”~/App_Data/%property{LogName}” /> …. </appender> This is dynamic — you just have to set the log4net property “LogName” before you initialize log4net. Thus, in your code any time … Read more
If the information that is available in the HttpContext is sufficient, that is, if the sample code you posted gives you the right answer (except for the MDC issue) and you would just rather just not write: HttpContext context = HttpContext.Current; if (context != null && context.User != null && context.User.Identity.IsAuthenticated) { MDC.Set(“user”, HttpContext.Current.User.Identity.Name); } … Read more
You generally should not add an app.config file to a class library project; it won’t be used without some painful bending and twisting on your part. It doesn’t hurt the library project at all – it just won’t do anything at all. Instead, you configure the application which is using your library; so the configuration … Read more
FINAL SOLUTION:1 For anyone who may stumble upon this in the future, here is what I did. I made the static class below: using log4net; using log4net.Repository.Hierarchy; using log4net.Core; using log4net.Appender; using log4net.Layout; namespace Spectrum.Logging { public class Logger { public static void Setup() { Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); PatternLayout patternLayout = new PatternLayout(); patternLayout.ConversionPattern … Read more