So I've done some looking around. Most of the threads I find seem related to people wanting to run log4net in their actual tests. Meaning they want log entries in their test class. I don't want log entries from my actual tests. But I do want the expected log entries from the code I am testing. This is my first time using Log4net. If I run the code on it's own, the log entries work. If I run a test, no log entries though. Im guessing it's not initialized properly or perhaps I don't have log4net setup correctly in my UnitTest (in appconfig or assembly maybe??). This is an MVC 5 application. Here is a basic example.
Nunit Test (basics):
public class MyTestClass
public void MyTest
var testVar = @"string";
public class MyProjectClass : Controller
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(MyProjectClass));
public static void Method(string myString)
If you look in the app.config for your main project, you should see a log4net config section that specifies the location of the log file.
You first need to add log4net to your
<configSections> like this:
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=220.127.116.11,
Culture=neutral, PublicKeyToken=1b44e1d426115821" />
You can then add a
<log4net> section to the
<configuration> tag. Documentation for this can be found here.