How to use App.config in a WPF application to configure log4net

I am currently working on a WPF version of an existing console application. In a console application, I use log4net to do all my logging. So I configured all my applications, etc. In the App.config file. Everything works fine in a console application.

Now I want to implement the same logging features in my WPF application. I have to say that im completely new in WPF, and this is my first WPF project. I just tried adding App.config (exactly the same) to my WPF project as it did in my console application. But that does not work. FileAppenders does not create files. But I also do not get any errors or warnings when compiling.

What do I need to do to get the same logging functions for log4net as in my console application? How to configure log4net (Appenders) in a WPF application?

thanks in advance

xxxxxx Edit xxxxxx

Based on Roberts' hint, I could solve it. I added

log4net.Config.XmlConfigurator.Configure() 

to the main window. Now my log works exactly the same as in my console application.

 public MainWindow() { // check if Application is already running // if it is running - Kill if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Length > 1) System.Diagnostics.Process.GetCurrentProcess().Kill(); log4net.Config.XmlConfigurator.Configure(); InitializeComponent(); } 
+6
source share
2 answers

You need to call log4net.Config.XmlConfigurator.Configure() at startup.

+8
source

just inside the Window Constructor just add this line like this

 public MainWindow() { log4net.Config.XmlConfigurator.Configure(); InitializeComponent(); //..... } 
+2
source

Source: https://habr.com/ru/post/973750/


All Articles