Question

Config of my log4net:

<log4net>
<appender name="ItemsChangeLogFileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
  <file value="\logs\ItemChangeLogs\itemLog.{date}.txt"/>
  <appendToFile value="true"/>
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%d %m%n"/>
  </layout>
</appender>
<root>
  <priority value="ALL"/>
  <appender-ref ref="ItemsChangeLogFileAppender"/>
</root>
<logger name="ItemsChangeLogger">
  <level value="ALL"/>
  <appender-ref ref="ItemsChangeLogFileAppender"/>          
</logger>

class:

public class LogEvents
{
    private static readonly ILog log = LogManager.GetLogger("ItemsChangeLogger");

    public LogEvents()
    {
        XmlConfigurator.Configure();

        log.Info("Some message");
    }

    public void Test(object sender, EventArgs args)
    {
        log.Info("Test");
    }
}

I want to read my logs but don't find my file.

In some question (here) I use answer but filepath is empty. How to solve this problem?

Was it helpful?

Solution

You have to read your configuration:

log4net.Config.XmlConfigurator.Configure("log4net.config");

This assumes the name of you configuration file is log4net.xml. The log4net.xml file has to be in your bin directory.

The \logs\ItemChangeLogs folder must exist on your file system. I would change that to something like: c:\logs\ItemChangeLogs, so you know log4net will find the dir on your c drive, instead of an other drive.

log4net configuration documentation

I normally configure log4net using an attribute in the assembly.cs file like:

// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top