Created
June 8, 2012 17:42
-
-
Save bobbychopra/2897163 to your computer and use it in GitHub Desktop.
Log4Net Configuration in WPF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<configuration> | |
<configSections> | |
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/> | |
</configSections> | |
<log4net> | |
<root> | |
<level value="DEBUG"/> | |
<appender-ref ref="SmtpAppender"/> | |
<appender-ref ref="LogFileAppender"/> | |
<appender-ref ref="ColoredConsoleAppender"/> | |
</root> | |
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender"> | |
<param name="File" value="C:\tagfileuploader-log.txt"/> | |
<param name="AppendToFile" value="true"/> | |
<rollingStyle value="Size"/> | |
<maxSizeRollBackups value="10"/> | |
<maximumFileSize value="1MB"/> | |
<staticLogFileName value="true"/> | |
<layout type="log4net.Layout.PatternLayout"> | |
<conversionPattern value="%date [%thread] %-5level %logger: %message%newline"/> | |
</layout> | |
</appender> | |
<appender name="ColoredConsoleAppender" type="log4net.Appender.ConsoleAppender"> | |
<layout type="log4net.Layout.PatternLayout"> | |
<conversionPattern value="%date [%thread] %-5level %logger: %message%newline"/> | |
</layout> | |
</appender> | |
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> | |
<to value="[email protected]"/> | |
<from value="[email protected]"/> | |
<subject value="TagFileUploader ERROR"/> | |
<smtpHost value="prc-mn-ex01"/> | |
<bufferSize value="512"/> | |
<lossy value="true"/> | |
<evaluator type="log4net.Core.LevelEvaluator"> | |
<threshold value="ERROR"/> | |
</evaluator> | |
<layout type="log4net.Layout.PatternLayout"> | |
<conversionPattern value="%date [%thread] %-5level %logger: %message%newline"/> | |
</layout> | |
</appender> | |
</log4net> | |
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows; | |
using log4net; | |
namespace Namespace | |
{ | |
/// <summary> | |
/// Interaction logic for App.xaml | |
/// </summary> | |
public partial class App : Application | |
{ | |
private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
protected override void OnStartup(StartupEventArgs e) | |
{ | |
log4net.Config.XmlConfigurator.Configure(); | |
//Log.Info("Hello World"); | |
base.OnStartup(e); | |
} | |
} | |
} |
For me the log is writing in to the file
Thanks for this.I got output.
The order is important, section should be before
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this! I have a mental block around log4net.Config.XmlConfigurator.Configure();