-
-
Save mizanRahman/4484020 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?> | |
<configuration> | |
<configSections> | |
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> | |
</configSections> | |
<log4net> | |
<root> | |
<level value="DEBUG" /> | |
<!--both colored-console-logging and file-logging is enabled--> | |
<appender-ref ref="LogFileAppender" /> | |
<appender-ref ref="ColoredConsoleAppender" /> | |
</root> | |
<!--log to file--> | |
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender" > | |
<param name="File" value="F:\\log.txt" /> | |
<param name="AppendToFile" value="true" /> | |
<rollingStyle value="Size" /> | |
<maxSizeRollBackups value="10" /> | |
<maximumFileSize value="10MB" /> | |
<staticLogFileName value="true" /> | |
<layout type="log4net.Layout.PatternLayout"> | |
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" /> | |
</layout> | |
</appender> | |
<!--colored log on console--> | |
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender"> | |
<mapping> | |
<level value="INFO" /> | |
<forecolor value="Green" /> | |
</mapping> | |
<mapping> | |
<level value="ERROR" /> | |
<forecolor value="Red" /> | |
</mapping> | |
<mapping> | |
<level value="DEBUG" /> | |
<forecolor value="Yellow" /> | |
</mapping> | |
<layout type="log4net.Layout.PatternLayout"> | |
<conversionpattern value="%date [%thread] %-5level - %message%newline" /> | |
</layout> | |
</appender> | |
</log4net> | |
<startup> | |
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> | |
</startup> | |
</configuration> |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using log4net; | |
using log4net.Config; | |
namespace LogForNetTest | |
{ | |
class Program | |
{ | |
protected static readonly ILog log = LogManager.GetLogger(typeof(Program)); | |
static void Main(string[] args) | |
{ | |
XmlConfigurator.Configure(); | |
#if DEBUG | |
log.Debug("Hello from debug"); //put this log while running in debug mode only | |
#endif | |
log.Info("This is just to inform you"); | |
log.Warn("Something you should consider. better check this out!!!"); | |
log.Error("oops!!something wrong"); | |
log.Fatal("you are dead, man!!!"); | |
Console.ReadLine(); | |
} | |
} | |
} |
When I modify my configuration, I get following error: ColoredConsoleAppender not found. I found that this appender is not available for dotnet core application.
I wanted to log error parts of my application as bold. I can't find any solution for formatting option in log4net.
Try log4net.Appender.ManagedColoredConsoleAppender
Hi,
I am using Log4net for logging my selenium C# tests. As I was able to print my Test Explorer logs in regular text but instead I want to print colorful output for different kind of log messages. So I have tried your above solution with log4net.Appender.ManagedColoredConsoleAppender but for some reason it doesn't show colorful output in Test Exlorer's output results window . Details are below:
my Log4net.config file
Any help would be appreciated!
it would be nice to have WARN colored too
<mapping>
<level value="WARN" />
<foreColor value="Yellow, HighIntensity" />
</mapping>
log4net