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”>

Log4Net config in external file does not work

Do you have the following attribute in your AssemblyInfo.cs file: [assembly: log4net.Config.XmlConfigurator(ConfigFile = “Log4Net.config”, Watch = true)] and code like this at the start of each class that requires logging functionality: private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); I have a blog post containing this and other info here.

How to disable creation of empty log file on app start?

I actually found a way to do this in this thread: http://www.l4ndash.com/Log4NetMailArchive/tabid/70/forumid/1/postid/18271/view/topic/Default.aspx I’ve tested the first method and it works. Just in case that link is not longer good I’ll reproduce the code here. Basically the author states that there are two ways of doing this. First way: Create a new locking model that only … Read more

How to log MethodName when wrapping Log4net?

What about the %M and %C variables? http://logging.apache.org/log4net/log4net-1.2.11/release/sdk/log4net.Layout.PatternLayout.html Usage, something like: <layout type=”log4net.Layout.PatternLayout”> <conversionPattern value=”%date [%thread] %-5level %logger [%M %C] – %message%newline” /> </layout> Doesn’t that do what you are after?

log4net one file per run

I assume that the application should create only one log file every time it runs, so you do not need a rolling file appender (though my solution would apply for rolling file appenders as well): <appender name=”FileAppender” type=”log4net.Appender.FileAppender”> <file type=”log4net.Util.PatternString” value=”c:\temp\App-%date{yyyy-MM-dd_HH-mm-ss}.log” /> <appendToFile value=”true” /> <layout type=”log4net.Layout.PatternLayout”> <conversionPattern value=”%date [%2thread] %-5level – %message%newline” /> </layout> … Read more

Log4net xml output

As suggested by MrPeregrination you need to write a class deriving from XmlLayoutBase, override the FormatXml method and instruct your appender to use it as layout: class Program { static void Main(string[] args) { XmlConfigurator.Configure(); ILog log = log4net.LogManager.GetLogger(typeof(Program)); log.Debug(“Hello world”); } } public class MyXmlLayout : XmlLayoutBase { protected override void FormatXml(XmlWriter writer, LoggingEvent … Read more