Skip to content

Commit 99b9ed1

Browse files
authored
Merge pull request #342 from sungam3r/c10
Implicit usings and file-scoped namespaces
2 parents bd0d0a4 + 34d6475 commit 99b9ed1

File tree

53 files changed

+3145
-3271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3145
-3271
lines changed

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ end_of_line = lf
1515

1616
[*.{cmd, bat}]
1717
end_of_line = crlf
18+
19+
csharp_style_namespace_declarations = file_scoped:suggestion

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<LangVersion>latest</LangVersion>
44
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
55
<TreatSpecificWarningsAsErrors />
6+
<ImplicitUsings>enable</ImplicitUsings>
67
</PropertyGroup>
78

89
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">

sample/Sample/Program.cs

Lines changed: 64 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
using System;
2-
3-
using System.IO;
4-
using System.Linq;
5-
using System.Collections.Generic;
6-
using System.Threading;
7-
8-
using Microsoft.Extensions.Configuration;
1+
using Microsoft.Extensions.Configuration;
92

103
using Serilog;
114
using Serilog.Core;
@@ -14,93 +7,92 @@
147

158
// ReSharper disable UnusedType.Global
169

17-
namespace Sample
10+
namespace Sample;
11+
12+
public class Program
1813
{
19-
public class Program
14+
public static void Main(string[] args)
2015
{
21-
public static void Main(string[] args)
22-
{
23-
SelfLog.Enable(Console.Error);
16+
SelfLog.Enable(Console.Error);
2417

25-
Thread.CurrentThread.Name = "Main thread";
18+
Thread.CurrentThread.Name = "Main thread";
2619

27-
var configuration = new ConfigurationBuilder()
28-
.SetBasePath(Directory.GetCurrentDirectory())
29-
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
30-
.Build();
20+
var configuration = new ConfigurationBuilder()
21+
.SetBasePath(Directory.GetCurrentDirectory())
22+
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
23+
.Build();
3124

32-
var logger = new LoggerConfiguration()
33-
.ReadFrom.Configuration(configuration)
34-
.CreateLogger();
25+
var logger = new LoggerConfiguration()
26+
.ReadFrom.Configuration(configuration)
27+
.CreateLogger();
3528

36-
logger.Information("Args: {Args}", args);
29+
logger.Information("Args: {Args}", args);
3730

38-
do
39-
{
40-
logger.ForContext<Program>().Information("Hello, world!");
41-
logger.ForContext<Program>().Error("Hello, world!");
42-
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Warning("Hello, world!");
43-
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Error("Hello, world!");
44-
logger.ForContext(Constants.SourceContextPropertyName, "MyApp.Something.Tricky").Verbose("Hello, world!");
31+
do
32+
{
33+
logger.ForContext<Program>().Information("Hello, world!");
34+
logger.ForContext<Program>().Error("Hello, world!");
35+
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Warning("Hello, world!");
36+
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Error("Hello, world!");
37+
logger.ForContext(Constants.SourceContextPropertyName, "MyApp.Something.Tricky").Verbose("Hello, world!");
4538

46-
logger.Information("Destructure with max object nesting depth:\n{@NestedObject}",
47-
new { FiveDeep = new { Two = new { Three = new { Four = new { Five = "the end" } } } } });
39+
logger.Information("Destructure with max object nesting depth:\n{@NestedObject}",
40+
new { FiveDeep = new { Two = new { Three = new { Four = new { Five = "the end" } } } } });
4841

49-
logger.Information("Destructure with max string length:\n{@LongString}",
50-
new { TwentyChars = "0123456789abcdefghij" });
42+
logger.Information("Destructure with max string length:\n{@LongString}",
43+
new { TwentyChars = "0123456789abcdefghij" });
5144

52-
logger.Information("Destructure with max collection count:\n{@BigData}",
53-
new { TenItems = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" } });
45+
logger.Information("Destructure with max collection count:\n{@BigData}",
46+
new { TenItems = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" } });
5447

55-
logger.Information("Destructure with policy to strip password:\n{@LoginData}",
56-
new LoginData { Username = "BGates", Password = "isityearoflinuxyet" });
48+
logger.Information("Destructure with policy to strip password:\n{@LoginData}",
49+
new LoginData { Username = "BGates", Password = "isityearoflinuxyet" });
5750

58-
Console.WriteLine("\nPress \"q\" to quit, or any other key to run again.\n");
59-
}
60-
while (!args.Contains("--run-once") && (Console.ReadKey().KeyChar != 'q'));
51+
Console.WriteLine("\nPress \"q\" to quit, or any other key to run again.\n");
6152
}
53+
while (!args.Contains("--run-once") && (Console.ReadKey().KeyChar != 'q'));
6254
}
55+
}
6356

64-
// The filter syntax in the sample configuration file is
65-
// processed by the Serilog.Filters.Expressions package.
66-
public class CustomFilter : ILogEventFilter
67-
{
68-
readonly LogEventLevel _levelFilter;
69-
70-
public CustomFilter(LogEventLevel levelFilter = LogEventLevel.Information)
71-
{
72-
_levelFilter = levelFilter;
73-
}
57+
// The filter syntax in the sample configuration file is
58+
// processed by the Serilog.Filters.Expressions package.
59+
public class CustomFilter : ILogEventFilter
60+
{
61+
readonly LogEventLevel _levelFilter;
7462

75-
public bool IsEnabled(LogEvent logEvent)
76-
{
77-
return logEvent.Level >= _levelFilter;
78-
}
63+
public CustomFilter(LogEventLevel levelFilter = LogEventLevel.Information)
64+
{
65+
_levelFilter = levelFilter;
7966
}
8067

81-
public class LoginData
68+
public bool IsEnabled(LogEvent logEvent)
8269
{
83-
public string Username;
84-
// ReSharper disable once NotAccessedField.Global
85-
public string Password;
70+
return logEvent.Level >= _levelFilter;
8671
}
72+
}
73+
74+
public class LoginData
75+
{
76+
public string Username;
77+
// ReSharper disable once NotAccessedField.Global
78+
public string Password;
79+
}
8780

88-
public class CustomPolicy : IDestructuringPolicy
81+
public class CustomPolicy : IDestructuringPolicy
82+
{
83+
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
8984
{
90-
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue result)
85+
result = null;
86+
87+
if (value is LoginData loginData)
9188
{
92-
result = null;
93-
94-
if (value is LoginData loginData)
95-
{
96-
result = new StructureValue(
97-
new List<LogEventProperty>
98-
{
99-
new("Username", new ScalarValue(loginData.Username))
100-
});
101-
}
102-
103-
return (result != null);
89+
result = new StructureValue(
90+
new List<LogEventProperty>
91+
{
92+
new("Username", new ScalarValue(loginData.Username))
93+
});
10494
}
95+
96+
return (result != null);
10597
}
10698
}

serilog-settings-configuration.sln.DotSettings

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
3-
2+
3+
44
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/AutoCompleteBasicCompletion/@EntryValue">True</s:Boolean>
55
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/CSharpCompletingCharacters/UpgradedFromVSSettings/@EntryValue">True</s:Boolean>
66
<s:Boolean x:Key="/Default/CodeEditing/Intellisense/CodeCompletion/IntelliSenseCompletingCharacters/IntelliSenseCompletingCharactersSettingCSharp/UpgradedFromVSSettings/@EntryValue">True</s:Boolean>
@@ -477,7 +477,7 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
477477
&lt;/Patterns&gt;&#xD;
478478
</s:String>
479479
<s:String x:Key="/Default/CodeStyle/CSharpMemberOrderPattern/LayoutType/@EntryValue">CustomLayout</s:String>
480-
480+
481481
<s:Boolean x:Key="/Default/CodeStyle/Generate/=Constructor/@KeyIndexDefined">True</s:Boolean>
482482
<s:String x:Key="/Default/CodeStyle/Generate/=Constructor/Options/=XmlDocumentation/@EntryIndexedValue">False</s:String>
483483
<s:Boolean x:Key="/Default/CodeStyle/Generate/=Equality/@KeyIndexDefined">True</s:Boolean>
@@ -551,11 +551,11 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
551551
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
552552
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
553553
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
554-
555-
556-
557-
554+
555+
556+
557+
558558
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String>
559559
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
560560
<s:Boolean x:Key="/Default/UserDictionary/Words/=Enricher/@EntryIndexedValue">True</s:Boolean>
561-
<s:Boolean x:Key="/Default/UserDictionary/Words/=polyfilled/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
561+
<s:Boolean x:Key="/Default/UserDictionary/Words/=polyfilled/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 commit comments

Comments
 (0)