Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check log4net log path?

My configuration file is :

<log4net  xsi:noNamespaceSchemaLocation="http://csharptest.net/downloads/schema/log4net.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <appender name="InfoFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="D:/" />
            <appendToFile value="true" />
            <param name="DatePattern" value="yyyyMMdd&quot;.txt&quot;" />
            <rollingStyle value="Date" />
            <maxSizeRollBackups value="100" />
            <datePattern value="YYYY-MM-DD'.log'"/>
            <maximumFileSize value="1024KB" />
            <staticLogFileName value="false" />
            <encoding value="utf-8"/>           
            <filter type="log4net.Filter.LevelRangeFilter">
                <param name="LevelMin" value="INFO" />
                <param name="LevelMax" value="INFO" />
            </filter>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date %-5level %logger  - %message%newline" />
            </layout>
        </appender>
        <appender name="ErrorFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="D:/" />
            <appendToFile value="true" />
            <rollingStyle value="Size" />
            <maxSizeRollBackups value="100" />
            <maximumFileSize value="10240KB" />
            <datePattern value="YYYY-MM-DD'.log'"/>
            <staticLogFileName value="true" />
            <encoding value="utf-8"/>
            <filter type="log4net.Filter.LevelRangeFilter">
                <param name="LevelMin" value="WARN" />
                <param name="LevelMax" value="FATAL" />
            </filter>
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date %-5level %logger - %message%newline" />
            </layout>
        </appender>
        <root>
            <level value="INFO" />
            <appender-ref ref="InfoFileAppender" />
            <appender-ref ref="ErrorFileAppender" />
        </root>
    </log4net>

in app.config.

But it has no log file in disk D:!!!!

like image 493
Dolphin Avatar asked Dec 20 '22 20:12

Dolphin


2 Answers

Just verified your config - works fine. You probably didn't initialize log4net properly. You should add into AssemblyInfo.cs file:

[assembly: XmlConfigurator(Watch = true)]

Or you can use XmlConfigurator.ConfigureAndWatch method or simply

XmlConfigurator.Configure();

Unlike NLog, log4net cannot initialize itself.

NOTES: You should change your date pattern to yyyy-MM-dd'.log' - year and day should be lowercase letters. Also you can write several levels with single appender. There is no need to create two appenders which write to same file.

like image 72
Sergey Berezovskiy Avatar answered Dec 22 '22 09:12

Sergey Berezovskiy


Try as below

<file value="D:/ABC.txt" />

assemblyinfo.cs

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "~\\Abc\\xyz\\log4net.config", Watch = true)]
like image 45
Amit Avatar answered Dec 22 '22 10:12

Amit