Skip to content

Commit 2c178c8

Browse files
committed
fix(NLog): support configuration of multiple rules per named Target
1 parent c6d348b commit 2c178c8

File tree

5 files changed

+69
-58
lines changed

5 files changed

+69
-58
lines changed

Diff for: .devcontainer/devcontainer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"dockerComposeFile": "docker-compose.yml",
99
"service": "app",
1010
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
11-
"forwardPorts": [1433]
11+
"forwardPorts": [1433]
1212
}

Diff for: .devcontainer/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
restart: unless-stopped
2020
environment:
2121
ACCEPT_EULA: Y
22-
MSSQL_SA_PASSWORD: ArkSpecFlow123Stella!
22+
MSSQL_SA_PASSWORD: SpecFlowLocalDbPassword85!
2323

2424
azurite:
2525
image: mcr.microsoft.com/azure-storage/azurite:latest

Diff for: Ark.ReferenceProject/Core/Ark.Reference.Core.Database/packages.lock.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
".NETFramework,Version=v4.6": {
55
"Meziantou.Analyzer": {
66
"type": "Direct",
7-
"requested": "[2.0.186, )",
8-
"resolved": "2.0.186",
9-
"contentHash": "PE8c9opHuUWLNqnZTN/KQC9oIfD/ZtsQ25sHF7/og4KfIRVnN4mgiyYw5NwCp8YPGapLoduIxuyQAcic6Eqcjg=="
7+
"requested": "[2.0.187, )",
8+
"resolved": "2.0.187",
9+
"contentHash": "s35YCC7rnWZnxtpdihrkdrGSAuzhdc+1kUMmO+UgVoogw3HAMmPO9BrSkxfU/KwhncK0Hr+nHFuAqOl+mGS01Q=="
1010
},
1111
"Microsoft.CodeAnalysis.NetAnalyzers": {
1212
"type": "Direct",

Diff for: Ark.ReferenceProject/Core/Ark.Reference.Core.Tests/packages.lock.json

+28-29
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,21 @@
9191
},
9292
"MSTest.TestAdapter": {
9393
"type": "Direct",
94-
"requested": "[3.7.3, )",
95-
"resolved": "3.7.3",
96-
"contentHash": "Ro3TnkC+TfovOTFd93DnzDF/ickJkkAYVmnzrjvY3FUduRcTJLIOJee9kiP1o3q1aPqmJSK6CobdvyWXubajWw==",
94+
"requested": "[3.8.0, )",
95+
"resolved": "3.8.0",
96+
"contentHash": "Z/wv8VduiO+sv3SB+Mm6QPQkvUSb01iz5WIdFnFXkPA8+e8+tEBYWYzdMLjHNpHAkCR2bZTDuCFpt8pabteQvA==",
9797
"dependencies": {
98-
"Microsoft.Testing.Extensions.VSTestBridge": "1.5.3",
99-
"Microsoft.Testing.Platform.MSBuild": "1.5.3"
98+
"Microsoft.Testing.Extensions.VSTestBridge": "1.6.0",
99+
"Microsoft.Testing.Platform.MSBuild": "1.6.0"
100100
}
101101
},
102102
"MSTest.TestFramework": {
103103
"type": "Direct",
104-
"requested": "[3.7.3, )",
105-
"resolved": "3.7.3",
106-
"contentHash": "Eg4F4zOsAFKlSiLI3tOJfg6BGXeppLhgdupAfVlnpZBXa3rNqxINIeZDJ5/KpoW5BRZyUSZW76Q8yNNk0GqCEQ==",
104+
"requested": "[3.8.0, )",
105+
"resolved": "3.8.0",
106+
"contentHash": "m8M90qrXK3a48+qfe9mgMGls34nqT44pjMy8nIowJa08fYVuCvAfwm416GGpf68AnxGeXCPdeYk2w+yRpCZ5cQ==",
107107
"dependencies": {
108-
"MSTest.Analyzers": "3.7.3"
108+
"MSTest.Analyzers": "3.8.0"
109109
}
110110
},
111111
"netDumbster": {
@@ -1685,44 +1685,43 @@
16851685
},
16861686
"Microsoft.Testing.Extensions.Telemetry": {
16871687
"type": "Transitive",
1688-
"resolved": "1.5.3",
1689-
"contentHash": "U9pGd5DQuX1PfkrdFI+xH34JGgQ2nes5QAwIITTk+MQfLvRITqsZjJeHTjpGWh33D/0q1l7aA8/LQHR7UuCgLQ==",
1688+
"resolved": "1.6.0",
1689+
"contentHash": "cAKU+vcti1jdLJYLffvoPutA80zfw5BbYpJp9yih0G0nSaUV2npl9SG/gfq1+kD7zi5PKe2ewnqnfKJ5xigB7A==",
16901690
"dependencies": {
16911691
"Microsoft.ApplicationInsights": "2.22.0",
1692-
"Microsoft.Testing.Platform": "1.5.3"
1692+
"Microsoft.Testing.Platform": "1.6.0"
16931693
}
16941694
},
16951695
"Microsoft.Testing.Extensions.TrxReport.Abstractions": {
16961696
"type": "Transitive",
1697-
"resolved": "1.5.3",
1698-
"contentHash": "h34zKNpGyni66VH738mRHeXSnf3klSShUdavUWNhSfWICUUi5aXeI0LBvoX/ad93N0+9xBDU3Fyi6WfxrwKQGw==",
1697+
"resolved": "1.6.0",
1698+
"contentHash": "ZJEmU/7TFgx3lkvTCJwerwLmiy0BdI9tny0JlwHUiJsxyt+GTl56bPWo7Z+lE5iMRLbxIQqdHVtLkMTzBkcAVQ==",
16991699
"dependencies": {
1700-
"Microsoft.Testing.Platform": "1.5.3"
1700+
"Microsoft.Testing.Platform": "1.6.0"
17011701
}
17021702
},
17031703
"Microsoft.Testing.Extensions.VSTestBridge": {
17041704
"type": "Transitive",
1705-
"resolved": "1.5.3",
1706-
"contentHash": "cJD67YfDT98wEWyazKVD/yPVW6+H1usXeuselCnRes7JZBTIYWtrCchcOzOahnmajT79eDKqt9sta7DXwTDU4Q==",
1705+
"resolved": "1.6.0",
1706+
"contentHash": "7vU5LaxETfeZn+M4G5cOtPkUWasn2SQnEHATLqDhWbhbdCK1eK0hM/5/EZiSUv/GS50UCTAU5JUpqfTv5OF5IA==",
17071707
"dependencies": {
1708-
"Microsoft.ApplicationInsights": "2.22.0",
1709-
"Microsoft.TestPlatform.ObjectModel": "17.12.0",
1710-
"Microsoft.Testing.Extensions.Telemetry": "1.5.3",
1711-
"Microsoft.Testing.Extensions.TrxReport.Abstractions": "1.5.3",
1712-
"Microsoft.Testing.Platform": "1.5.3"
1708+
"Microsoft.TestPlatform.ObjectModel": "17.13.0",
1709+
"Microsoft.Testing.Extensions.Telemetry": "1.6.0",
1710+
"Microsoft.Testing.Extensions.TrxReport.Abstractions": "1.6.0",
1711+
"Microsoft.Testing.Platform": "1.6.0"
17131712
}
17141713
},
17151714
"Microsoft.Testing.Platform": {
17161715
"type": "Transitive",
1717-
"resolved": "1.5.3",
1718-
"contentHash": "WqJydnJ99dEKtquR9HwINz104ehWJKTXbQQrydGatlLRw14bmsx0pa8+E6KUXMYXZAimN0swWlDmcJGjjW4TIg=="
1716+
"resolved": "1.6.0",
1717+
"contentHash": "4KxRjDHeZnOx7+ZCqbAqrQNWA1Es552jY7/9z/CKVHkbkfc6nnAGE8Xq060lqauBENuqs/oD2uid/qY9Q4qwNA=="
17191718
},
17201719
"Microsoft.Testing.Platform.MSBuild": {
17211720
"type": "Transitive",
1722-
"resolved": "1.5.3",
1723-
"contentHash": "bOtpRMSPeT5YLQo+NNY8EtdNTphAUcmALjW4ABU7P0rb6yR2XAZau3TzNieLmR3lRuwudguWzzBhgcLRXwZh0A==",
1721+
"resolved": "1.6.0",
1722+
"contentHash": "9o7+Bl3UNWikzbQawdhllnO/tUwaYIy/urVwNyTmhhCBt9GCK9fsdl4GLqg9UBgNEcyoZd8lr+Vhubo9vFMDkg==",
17241723
"dependencies": {
1725-
"Microsoft.Testing.Platform": "1.5.3"
1724+
"Microsoft.Testing.Platform": "1.6.0"
17261725
}
17271726
},
17281727
"Microsoft.TestPlatform.ObjectModel": {
@@ -1792,8 +1791,8 @@
17921791
},
17931792
"MSTest.Analyzers": {
17941793
"type": "Transitive",
1795-
"resolved": "3.7.3",
1796-
"contentHash": "5KcyyxIP0UBRKBs135+S3JQJALc1PmZMzhpR86JIXQ2Dnd/lDiOGNDD8R23X015mWi1K95KQWsGWw+3e7DUrgg=="
1794+
"resolved": "3.8.0",
1795+
"contentHash": "AsA4zzPU2GFW3pMn0bY1/vXhrbRXNzltAU8EhqEit172XU3zazihr5bBPqb5IKVWTlvEIkMCDUoqJKs/IprQZQ=="
17971796
},
17981797
"NetEscapades.AspNetCore.SecurityHeaders": {
17991798
"type": "Transitive",

Diff for: Ark.Tools.NLog/NlogConfigurer.cs

+36-24
Original file line numberDiff line numberDiff line change
@@ -451,101 +451,113 @@ public Configurer WithMailTarget(string? from, string to, string smtpConnectionS
451451
public Configurer WithSlackRule(string loggerPattern, LogLevel level, bool final = false)
452452
{
453453
var target = _config.FindTargetByName(SlackTarget);
454-
_config.RemoveRuleByName(SlackTarget);
455-
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = SlackTarget, Final = final });
454+
var ruleName = $"{SlackTarget}-{loggerPattern}";
455+
_config.RemoveRuleByName(ruleName);
456+
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ruleName, Final = final });
456457

457458
return this;
458459
}
459460
public Configurer WithSlackRule(string loggerPattern, LogLevel minLevel, LogLevel maxLevel, bool final = false)
460461
{
461462
var target = _config.FindTargetByName(SlackTarget);
462-
_config.RemoveRuleByName(SlackTarget);
463-
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = SlackTarget, Final = final });
463+
var ruleName = $"{SlackTarget}-{loggerPattern}";
464+
_config.RemoveRuleByName(ruleName);
465+
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ruleName, Final = final });
464466

465467
return this;
466468
}
467469

468470
public Configurer WithApplicationInsightsRule(string loggerPattern, LogLevel level, bool final = false)
469471
{
470472
var target = _config.FindTargetByName(ApplicationInsightsTarget);
471-
_config.RemoveRuleByName(ApplicationInsightsTarget);
472-
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ApplicationInsightsTarget, Final = final });
473+
var ruleName = $"{ApplicationInsightsTarget}-{loggerPattern}";
474+
_config.RemoveRuleByName(ruleName);
475+
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ruleName, Final = final });
473476

474477
return this;
475478
}
476479
public Configurer WithApplicationInsightsRule(string loggerPattern, LogLevel minLevel, LogLevel maxLevel, bool final = false)
477480
{
478481
var target = _config.FindTargetByName(ApplicationInsightsTarget);
479-
_config.RemoveRuleByName(ApplicationInsightsTarget);
480-
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ApplicationInsightsTarget, Final = final });
482+
var ruleName = $"{ApplicationInsightsTarget}-{loggerPattern}";
483+
_config.RemoveRuleByName(ruleName);
484+
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ruleName, Final = final });
481485

482486
return this;
483487
}
484488

485489
public Configurer WithConsoleRule(string loggerPattern, LogLevel level, bool final = false)
486490
{
487491
var target = _config.FindTargetByName(ConsoleTarget);
488-
_config.RemoveRuleByName(ConsoleTarget);
489-
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ConsoleTarget, Final = final });
492+
var ruleName = $"{ConsoleTarget}-{loggerPattern}";
493+
_config.RemoveRuleByName(ruleName);
494+
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ruleName, Final = final });
490495

491496
return this;
492497
}
493498
public Configurer WithConsoleRule(string loggerPattern, LogLevel minLevel, LogLevel maxLevel, bool final = false)
494499
{
495500
var target = _config.FindTargetByName(ConsoleTarget);
496-
_config.RemoveRuleByName(ConsoleTarget);
497-
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ConsoleTarget, Final = final });
501+
var ruleName = $"{ConsoleTarget}-{loggerPattern}";
502+
_config.RemoveRuleByName(ruleName);
503+
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ruleName, Final = final });
498504

499505
return this;
500506
}
501507

502508
public Configurer WithDatabaseRule(string loggerPattern, LogLevel level, bool final = false)
503509
{
504510
var target = _config.FindTargetByName(DatabaseTarget);
505-
_config.RemoveRuleByName(DatabaseTarget);
506-
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = DatabaseTarget, Final = final });
511+
var ruleName = $"{DatabaseTarget}-{loggerPattern}";
512+
_config.RemoveRuleByName(ruleName);
513+
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ruleName, Final = final });
507514

508515
return this;
509516
}
510517
public Configurer WithDatabaseRule(string loggerPattern, LogLevel minLevel, LogLevel maxLevel, bool final = false)
511518
{
512519
var target = _config.FindTargetByName(DatabaseTarget);
513-
_config.RemoveRuleByName(DatabaseTarget);
514-
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = DatabaseTarget, Final = final });
520+
var ruleName = $"{DatabaseTarget}-{loggerPattern}";
521+
_config.RemoveRuleByName(ruleName);
522+
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ruleName, Final = final });
515523

516524
return this;
517525
}
518526

519527
public Configurer WithFileRule(string loggerPattern, LogLevel level, bool final = false)
520528
{
521529
var target = _config.FindTargetByName(FileTarget);
522-
_config.RemoveRuleByName(FileTarget);
523-
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = FileTarget, Final = final });
530+
var ruleName = $"{FileTarget}-{loggerPattern}";
531+
_config.RemoveRuleByName(ruleName);
532+
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ruleName, Final = final });
524533

525534
return this;
526535
}
527536
public Configurer WithFileRule(string loggerPattern, LogLevel minLevel, LogLevel maxLevel, bool final = false)
528537
{
529538
var target = _config.FindTargetByName(FileTarget);
530-
_config.RemoveRuleByName(FileTarget);
531-
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = FileTarget, Final = final });
539+
var ruleName = $"{FileTarget}-{loggerPattern}";
540+
_config.RemoveRuleByName(ruleName);
541+
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ruleName, Final = final });
532542

533543
return this;
534544
}
535545

536546
public Configurer WithMailRule(string loggerPattern, LogLevel level, bool final = false)
537547
{
538548
var target = _config.FindTargetByName(MailTarget);
539-
_config.RemoveRuleByName(MailTarget);
540-
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = MailTarget, Final = final });
549+
var ruleName = $"{MailTarget}-{loggerPattern}";
550+
_config.RemoveRuleByName(ruleName);
551+
_config.AddRule(new LoggingRule(loggerPattern, level, target) { RuleName = ruleName, Final = final });
541552

542553
return this;
543554
}
544555
public Configurer WithMailRule(string loggerPattern, LogLevel minLevel, LogLevel maxLevel, bool final = false)
545556
{
546557
var target = _config.FindTargetByName(MailTarget);
547-
_config.RemoveRuleByName(MailTarget);
548-
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = MailTarget, Final = final });
558+
var ruleName = $"{MailTarget}-{loggerPattern}";
559+
_config.RemoveRuleByName(ruleName);
560+
_config.AddRule(new LoggingRule(loggerPattern, minLevel, maxLevel, target) { RuleName = ruleName, Final = final });
549561

550562
return this;
551563
}

0 commit comments

Comments
 (0)