Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
2.4k views
by Contributing Tester (48 points)
edited by
I am working on Selenium Web Driver project using C# VisualStudio, I have added refrence of log4net.dll  and Configured in Appconfig file as below :

<?xml version="1.0" encoding="utf-8"?>

<configuration>

<!-- Log4net setup -->

  <log4net>

    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">

      <file type="log4net.Util.PatternString" value="Logs\Automation-%date{dd-MM-yyyy_HH-mm-ss}.log" />

      <appendToFile value="false" />

      <maxSizeRollBackups value="-1" />

      <!--infinite-->

      <staticLogFileName value="true" />

      <rollingStyle value="Once" />

      <layout type="log4net.Layout.PatternLayout">

        <conversionPattern value="%-5level %date [%thread] %c{1} - %m%n" />

      </layout>

    </appender>

    <root>

      <!-- Valid log levels are: OFF, DEBUG, INFO, WARN, ERROR, FATAL, ALL -->

      <level value="All" />

      <appender-ref ref="RollingFileAppender" />

    </root>

  </log4net>

</configuration>

BaseTest.cs file:

Make object as below:

protected static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

TCTest01.cs

In TestScript ,used code as below:

log.Info("Verify login sucessfully");

You can check above configuration that, I have given file type and file value as below:

 <file type="log4net.Util.PatternString" value="Logs\Automation-%date{dd-MM-yyyy_HH-mm-ss}.log" />

but in my project, log is not printing  as per configuration logs should be print in \Logs sub folder of project root folder.

Please help me for this issue.

2 Answers

1 like 0 dislike
by Contributing Tester (48 points)
selected by
 
Best answer

Solution:

Open AssemblyInfo.cs file under Properties, then add the below line of code under the [assembly: AssemblyCulture("")] line.

// Let log4net know that it can look for configuration in the default application config file

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

by The go-to Tester (181 points)
Thank you for posting your solution.
0 like 1 dislike
by

Your valid log level are 

 

      <!-- Valid log levels are: OFF, DEBUG, INFO, WARN, ERROR, FATAL, ALL -->
But you have mentioined it as 
 
<level value="All" />
 
It should be
 
<level value="ALL" />
 
Right? Its supposed to be case sensitive.
by Contributing Tester (48 points)
Thanks for your reply, I will modify as per you suggest and get back to you :-)


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...