Skip to content

Commit 692eee8

Browse files
committed
⚗️ try to repro LOG4NET-681, without success
1 parent 71aa522 commit 692eee8

File tree

5 files changed

+111
-3
lines changed

5 files changed

+111
-3
lines changed

src/integration-testing/log4net-611-main/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// See https://aka.ms/new-console-template for more information
2-
3-
using System.Reflection;
1+
using System.Reflection;
42
using log4net;
53
using log4net.Config;
64
using log4net_611_lib;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System.Reflection;
2+
using log4net;
3+
using log4net.Config;
4+
5+
var appPath = new Uri(Assembly.GetExecutingAssembly().Location).LocalPath;
6+
var appFolder = Path.GetDirectoryName(appPath);
7+
8+
if (appFolder is null)
9+
{
10+
throw new InvalidOperationException("Can't find myself");
11+
}
12+
13+
var configFile = Path.Combine(appFolder, "log4net.config");
14+
if (!File.Exists(configFile))
15+
{
16+
throw new InvalidOperationException($"log4net.config not found at {configFile}");
17+
}
18+
19+
if (Directory.Exists("Logs"))
20+
{
21+
Console.WriteLine("Clearing out old logs...");
22+
foreach (var file in Directory.EnumerateFiles("Logs"))
23+
{
24+
File.Delete(file);
25+
}
26+
}
27+
28+
var info = new FileInfo(configFile);
29+
var logRepo = LogManager.GetRepository(Assembly.GetExecutingAssembly());
30+
XmlConfigurator.ConfigureAndWatch(
31+
logRepo,
32+
info
33+
);
34+
35+
var logger = LogManager.GetLogger(typeof(Program));
36+
37+
Console.WriteLine("logging...");
38+
var threads = new List<Thread>();
39+
for (var i = 0; i < 128; i++)
40+
{
41+
var thread = new Thread(LogABit);
42+
thread.Start();
43+
threads.Add(thread);
44+
}
45+
46+
foreach (var t in threads)
47+
{
48+
t.Join();
49+
}
50+
51+
foreach (var file in Directory.EnumerateFiles("Logs"))
52+
{
53+
Console.WriteLine($"found log file: {file}");
54+
}
55+
56+
void LogABit()
57+
{
58+
for (var i = 0; i < 100; i++)
59+
{
60+
logger.Info($"test log {i}");
61+
}
62+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>log4net_681</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\log4net\log4net.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="log4net.config">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<log4net>
2+
<appender name="LogFileAppenderXML" type="log4net.Appender.RollingFileAppender">
3+
<file value="Logs\.xml" />
4+
<datePattern value="yyyy-MM-dd-HH-mm-ss'Xyz'" />
5+
<appendToFile value="true" />
6+
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
7+
<rollingStyle value="Composite" />
8+
<maxSizeRollBackups value="40" />
9+
<maximumFileSize value="64" />
10+
<preserveLogFileNameExtension value="true" />
11+
<staticLogFileName value="false" />
12+
<layout type="log4net.Layout.PatternLayout">
13+
<conversionPattern value="[file] %message%newline" />
14+
</layout>
15+
</appender>
16+
<root>
17+
<level value="ALL"/>
18+
<appender-ref ref="LogFileAppenderXML" />
19+
</root>
20+
</log4net>

src/log4net.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-611-lib", "integrat
3434
EndProject
3535
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-673", "integration-testing\log4net-673\log4net-673.csproj", "{169118A6-CAC3-4E83-ABEE-9E884B75B294}"
3636
EndProject
37+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-681", "integration-testing\log4net-681\log4net-681.csproj", "{A4F9E417-2250-4075-9118-B4FF1C58B6C5}"
38+
EndProject
3739
Global
3840
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3941
Debug|Any CPU = Debug|Any CPU
@@ -64,6 +66,10 @@ Global
6466
{169118A6-CAC3-4E83-ABEE-9E884B75B294}.Debug|Any CPU.Build.0 = Debug|Any CPU
6567
{169118A6-CAC3-4E83-ABEE-9E884B75B294}.Release|Any CPU.ActiveCfg = Release|Any CPU
6668
{169118A6-CAC3-4E83-ABEE-9E884B75B294}.Release|Any CPU.Build.0 = Release|Any CPU
69+
{A4F9E417-2250-4075-9118-B4FF1C58B6C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
70+
{A4F9E417-2250-4075-9118-B4FF1C58B6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
71+
{A4F9E417-2250-4075-9118-B4FF1C58B6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
72+
{A4F9E417-2250-4075-9118-B4FF1C58B6C5}.Release|Any CPU.Build.0 = Release|Any CPU
6773
EndGlobalSection
6874
GlobalSection(SolutionProperties) = preSolution
6975
HideSolutionNode = FALSE
@@ -73,5 +79,6 @@ Global
7379
{2087EDC5-689F-406C-947C-06C5F321CA8C} = {8953473C-EEE8-4740-993D-B8E10FA876CD}
7480
{D818035F-0345-49EF-9AB9-021583986CE2} = {8953473C-EEE8-4740-993D-B8E10FA876CD}
7581
{169118A6-CAC3-4E83-ABEE-9E884B75B294} = {8953473C-EEE8-4740-993D-B8E10FA876CD}
82+
{A4F9E417-2250-4075-9118-B4FF1C58B6C5} = {8953473C-EEE8-4740-993D-B8E10FA876CD}
7683
EndGlobalSection
7784
EndGlobal

0 commit comments

Comments
 (0)