Im trying to use log4net in Unity and it seems there’s not much information about it. It’s possible? I downloaded in Visual Studio from NuGet, I copied the DLL into Unity’s Plugin folder, I requiered it by “using log4net” in the top of my file, I added
private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
to my class. But I don’t know how I can configure log4net or WHERE is logging! How can I do that?
Have you used log4net before? There are plenty of tutorials online on how to configure it. The brief version is that:
- You’ll want to have an XML file somewhere you can read that tells log4net what it’s supposed to do.
- Call
XmlConfigurator.Configure(...)
in the log4net assembly where the parameter is some sort of stream or file reader to that XML file. You’ll want to make this call before logging anything – usually at the start of your program.
The XML configuration files aren’t super easy to understand. Here’s an example (replace the file path in it with your own file.
<log4net>
<appender name="EventLog" type="log4net.Appender.RollingFileAppender">
<file value="Some\Path\You\Want\To\Save\To\events.log" />
<appendToFile value="true" />
<rollingStyle value="Once" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level in [%thread] %logger%newline%message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="EventLog" />
</root>
</log4net>