-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add synchronization to TextWriterLogComponent + several minor tweaks
- Loading branch information
1 parent
45958be
commit 499b753
Showing
7 changed files
with
190 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
[*.cs] | ||
|
||
# IDE0290: Use primary constructor | ||
# Primary constructors interfere with documentation clarity even though they're cool | ||
csharp_style_prefer_primary_constructors = false:suggestion | ||
csharp_indent_labels = no_change | ||
csharp_using_directive_placement = outside_namespace:silent | ||
csharp_prefer_simple_using_statement = true:suggestion | ||
csharp_prefer_braces = true:silent | ||
csharp_style_namespace_declarations = file_scoped:suggestion | ||
csharp_style_prefer_method_group_conversion = true:suggestion | ||
csharp_style_prefer_top_level_statements = false:warning | ||
csharp_style_expression_bodied_methods = false:silent | ||
csharp_style_expression_bodied_constructors = false:silent | ||
csharp_style_expression_bodied_operators = false:silent | ||
csharp_style_expression_bodied_properties = true:silent | ||
csharp_style_expression_bodied_indexers = true:silent | ||
csharp_style_expression_bodied_accessors = true:silent | ||
csharp_style_expression_bodied_lambdas = true:suggestion | ||
csharp_style_expression_bodied_local_functions = false:silent | ||
|
||
[*.{cs,vb}] | ||
dotnet_style_operator_placement_when_wrapping = beginning_of_line | ||
tab_width = 4 | ||
indent_size = 4 | ||
end_of_line = crlf | ||
dotnet_style_coalesce_expression = true:suggestion | ||
dotnet_style_null_propagation = true:suggestion | ||
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion | ||
dotnet_style_prefer_auto_properties = true:silent | ||
dotnet_style_object_initializer = true:suggestion | ||
dotnet_style_prefer_collection_expression = true:suggestion | ||
dotnet_style_collection_initializer = true:suggestion | ||
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion | ||
[*.cs] | ||
#### Naming styles #### | ||
|
||
# Naming rules | ||
|
||
dotnet_naming_rule.private_or_internal_field_should_be_begins_with_underscore.severity = suggestion | ||
dotnet_naming_rule.private_or_internal_field_should_be_begins_with_underscore.symbols = private_or_internal_field | ||
dotnet_naming_rule.private_or_internal_field_should_be_begins_with_underscore.style = begins_with_underscore | ||
|
||
# Symbol specifications | ||
|
||
dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field | ||
dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private, private_protected | ||
dotnet_naming_symbols.private_or_internal_field.required_modifiers = | ||
|
||
# Naming styles | ||
|
||
dotnet_naming_style.begins_with_underscore.required_prefix = _ | ||
dotnet_naming_style.begins_with_underscore.required_suffix = | ||
dotnet_naming_style.begins_with_underscore.word_separator = | ||
dotnet_naming_style.begins_with_underscore.capitalization = camel_case | ||
|
||
[*.{cs,vb}] | ||
#### Naming styles #### | ||
|
||
# Naming rules | ||
|
||
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion | ||
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface | ||
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i | ||
|
||
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion | ||
dotnet_naming_rule.types_should_be_pascal_case.symbols = types | ||
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case | ||
|
||
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion | ||
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members | ||
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case | ||
|
||
# Symbol specifications | ||
|
||
dotnet_naming_symbols.interface.applicable_kinds = interface | ||
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.interface.required_modifiers = | ||
|
||
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum | ||
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.types.required_modifiers = | ||
|
||
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method | ||
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected | ||
dotnet_naming_symbols.non_field_members.required_modifiers = | ||
|
||
# Naming styles | ||
|
||
dotnet_naming_style.begins_with_i.required_prefix = I | ||
dotnet_naming_style.begins_with_i.required_suffix = | ||
dotnet_naming_style.begins_with_i.word_separator = | ||
dotnet_naming_style.begins_with_i.capitalization = pascal_case | ||
|
||
dotnet_naming_style.pascal_case.required_prefix = | ||
dotnet_naming_style.pascal_case.required_suffix = | ||
dotnet_naming_style.pascal_case.word_separator = | ||
dotnet_naming_style.pascal_case.capitalization = pascal_case | ||
|
||
dotnet_naming_style.pascal_case.required_prefix = | ||
dotnet_naming_style.pascal_case.required_suffix = | ||
dotnet_naming_style.pascal_case.word_separator = | ||
dotnet_naming_style.pascal_case.capitalization = pascal_case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.IO; | ||
|
||
namespace d9.utl; | ||
/// <summary> | ||
/// An <see cref="ILogComponent"/> which wraps a <see cref="TextWriter"/> and allows it to be disposed. | ||
/// </summary> | ||
public class TextWriterLogComponent | ||
: ILogComponent, IDisposable, IAsyncDisposable | ||
{ | ||
private readonly TextWriter _writer; | ||
private bool _disposed = false; | ||
/// <summary> | ||
/// Creates a <see cref="TextWriterLogComponent"/> from the specified <paramref name="textWriter"/>. | ||
/// </summary> | ||
/// <param name="textWriter">The <see cref="TextWriter"/> from which to create the component.</param> | ||
/// <param name="synchronize">If <see langword="true"/>, the underlying writer will be a <see href="https://learn.microsoft.com/en-us/dotnet/api/system.io.textwriter.synchronized">synchronized</see> wrapper and therefore thread-safe.</param> | ||
public TextWriterLogComponent(TextWriter textWriter, bool synchronize = false) | ||
=> _writer = synchronize? TextWriter.Synchronized(textWriter) : textWriter; | ||
/// <summary> | ||
/// Creates a <see cref="TextWriterLogComponent"/> from the specified <paramref name="stream"/> by creating a <see cref="StreamWriter"/> which writes to it. | ||
/// </summary> | ||
/// <param name="stream">The <see cref="Stream"/> from which to create the component.</param> | ||
/// <remarks><b>NOTE:</b> disposing this component will dispose the <see cref="StreamWriter"/> it creates, and therefore the <see cref="Stream"/> you pass in.</remarks> | ||
/// <param name="synchronize"><inheritdoc cref="TextWriterLogComponent(TextWriter, bool)" path="/param[@name='synchronize']"/></param> | ||
public TextWriterLogComponent(Stream stream, bool synchronize = false) : this(new StreamWriter(stream), synchronize) { } | ||
/// <inheritdoc cref="ILogComponent.Write(object?)"/> | ||
public Task Write(object? obj) | ||
=> _writer.WriteAsync($"{obj}"); | ||
/// <inheritdoc cref="ILogComponent.WriteLine(object?)"/> | ||
public Task WriteLine(object? obj) | ||
=> _writer.WriteLineAsync($"{obj}"); | ||
/// <summary> | ||
/// Implements <see cref="IDisposable"/>. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
if (!_disposed) | ||
{ | ||
_disposed = true; | ||
_writer.Dispose(); | ||
} | ||
GC.SuppressFinalize(this); | ||
} | ||
/// <summary> | ||
/// Implements <see cref="IAsyncDisposable"/>. | ||
/// </summary> | ||
public async ValueTask DisposeAsync() | ||
{ | ||
if (!_disposed) | ||
{ | ||
_disposed = true; | ||
await _writer.DisposeAsync(); | ||
} | ||
GC.SuppressFinalize(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace d9.utl; | ||
internal class Tests_Log | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters