How I can set log4net to log my files into different folders each day?

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]&#13;&#10;” /> <footer value=”[Footer]&#13;&#10;” /> <conversionPattern value=”%date [%thread] %-5level %logger [%ndc] &lt;%property{auth}&gt; – %message%newline” /> </layout> </appender> It will create a logfile named ‘logs\2010\04\02.inf.log’ (let date be … Read more

Log4Net Logging of two different levels to two different appenders for the same logger

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

log4net – Appenders not working in IIS7.5

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

Log4Net, how to add a custom field to my logging

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

Best way to dynamically set an appender file path

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

Capture username with log4net

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

Can you configure log4net in code instead of using a config file?

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