I make two logger.
When i Start this project, LogFile and LogFolder is working.
The contents of the log operate abnormally.
Error:
- The contents of the log are mixed.
- The contents not contain Time.
Why My logger is not work correct??
This is my xaml code
Two button is exist.
<Window x:Class="LogTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:LogTest"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel>
<Button Content="ALog Btn" Click="Button_Click"/>
<Button Content="BLog Btn" Click="Button_Click_1"/>
</StackPanel>
</Grid>
</Window>
This is behind code.
I want multiple logger.
So i make two logger
using log4net;
using log4net.Appender;
using log4net.Config;
using log4net.Layout;
using log4net.Repository.Hierarchy;
using System;
using System.Windows;
namespace LogTest
{
public partial class MainWindow : Window
{
private ILog aLogger;
private ILog bLogger;
public MainWindow()
{
InitializeComponent();
aLogger = NewMethod("LogA");
bLogger = NewMethod("LogB");
}
private ILog NewMethod(string logFileBaseName)
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var rollingFileAppender = new RollingFileAppender()
{
Name = $"{logFileBaseName}File",
File = $"{Environment.CurrentDirectory}\Logs\{logFileBaseName}\",
DatePattern = string.Format("yyyy-MM-dd'.log'"),
StaticLogFileName = false,
AppendToFile = true,
RollingStyle = RollingFileAppender.RollingMode.Composite,
MaxSizeRollBackups = 100,
MaximumFileSize = "100MB",
Layout = new PatternLayout() { ConversionPattern = "[%date][%level] %message %newline" }
};
rollingFileAppender.ActivateOptions();
hierarchy.Root.AddAppender(rollingFileAppender);
hierarchy.Root.Level = log4net.Core.Level.All;
hierarchy.Configured = true;
XmlConfigurator.Configure(hierarchy);
return LogManager.GetLogger(rollingFileAppender.Name);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
aLogger.Debug("LogA Clicked");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
bLogger.Debug("LogB Clicked");
}
}
}
This is my App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net></log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>