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

Have log4net use application config file for configuration data

Add a line to your app.config in the configSections element <configSections> <section name=”log4net” type=”log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821″ /> </configSections> Then later add the log4Net section, but delegate to the actual log4Net config file elsewhere… <log4net configSource=”Config\Log4Net.config” /> In your application code, when you create the log, write private static ILog GetLog(string logName) { ILog … Read more

What would a Log4Net Wrapper class look like?

Essentially you create an interface and then a concrete implementation of that interface that wraps the classes and methods of Log4net directly. Additional logging systems can be wrapped by creating more concrete classes which wrap other classes and methods of those systems. Finally use a factory to create instances of your wrappers based on a … Read more

Is there a way to programmably flush the buffer in log4net

Assuming you’re using log4net out of the box, you can dig your way down & flush the appender like this: public void FlushBuffers() { ILog log = LogManager.GetLogger(“whatever”); var logger = log.Logger as Logger; if (logger != null) { foreach (IAppender appender in logger.Appenders) { var buffered = appender as BufferingAppenderSkeleton; if (buffered != null) … Read more

Log4Net “Could not find schema information” messages

You can bind in a schema to the log4net element. There are a few floating around, most do not fully provide for the various options available. I created the following xsd to provide as much verification as possible: http://csharptest.net/downloads/schema/log4net.xsd You can bind it into the xml easily by modifying the log4net element: <log4net xsi:noNamespaceSchemaLocation=”http://csharptest.net/downloads/schema/log4net.xsd” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>

When to use ‘nested diagnostic context’ (NDC)?

Want an example? Take the following Web API written using ASP.NET MVC4: // GET api/HypervResource public string Get() { logger.Debug(“Start of service test”); System.Threading.Thread.Sleep(5000); // simulate work logger.Debug(“End of service test”); return “HypervResource controller running, use POST to send JSON encoded RPCs”; } When server concurrent HTTP Requests are made, the logging can get interleaved. … Read more

Change log4net logging level programmatically

None of these solutions present here worked for me. It wasn’t changing at runtime Here is what worked for me: ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Root.Level = Level.Debug; ((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).RaiseConfigurationChanged(EventArgs.Empty); You have to call RaiseConfigurationChanged after making changes to its config.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)