diff --git a/.editorconfig b/.editorconfig
index 3b4dc1c76..94c6dbe63 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,279 +1,287 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true
#### Core EditorConfig Options ####
# All files
[*]
# General
charset = utf-8
trim_trailing_whitespace = true
# Indentation and spacing
indent_size = 4
indent_style =tab
tab_width = 4
# New line preferences
end_of_line = crlf
insert_final_newline = true
dotnet_style_readonly_field=true:suggestion
# Project files
[*.{csproj,targets,yml}]
indent_size = 2
[NuGet.config]
indent_size = 2
# Solution files
[*.sln]
indent_style = tab
tab_width = 4
#### .NET Coding Conventions ####
# C# files
[*.cs]
# Organize usings
dotnet_separate_import_directive_groups = false
dotnet_sort_system_directives_first = true
file_header_template = This file is part of the DisCatSharp project, based off DSharpPlus.\n\nCopyright (c) 2021 AITSYS\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.
# this. and Me. preferences
dotnet_style_qualification_for_event = true:warning
dotnet_style_qualification_for_field = true:warning
dotnet_style_qualification_for_method = true:warning
dotnet_style_qualification_for_property = true:warning
# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:warning
# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:suggestion
# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members
# Expression-level preferences
dotnet_style_coalesce_expression = true:warning
dotnet_style_collection_initializer = true
dotnet_style_explicit_tuple_names = true:warning
dotnet_style_null_propagation = true:warning
dotnet_style_object_initializer = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_compound_assignment = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = true:warning
dotnet_style_prefer_conditional_expression_over_return = true:warning
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:error
dotnet_style_prefer_simplified_boolean_expressions = true
dotnet_style_prefer_simplified_interpolation = true
# Field preferences
dotnet_style_readonly_field = true:warning
# Parameter preferences
dotnet_code_quality_unused_parameters = non_public
# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none
#### C# Coding Conventions ####
# var preferences
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:warning
# Expression-bodied members
csharp_style_expression_bodied_accessors = when_on_single_line:warning
csharp_style_expression_bodied_constructors = false:warning
csharp_style_expression_bodied_indexers = when_on_single_line:warning
csharp_style_expression_bodied_lambdas = true:warning
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
csharp_style_expression_bodied_methods = when_on_single_line:warning
csharp_style_expression_bodied_operators = when_on_single_line:warning
csharp_style_expression_bodied_properties = when_on_single_line:warning
# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_prefer_not_pattern = true:warning
csharp_style_prefer_pattern_matching = false
csharp_style_prefer_switch_expression = true
# Null-checking preferences
csharp_style_conditional_delegate_call = false
# Modifier preferences
csharp_prefer_static_local_function = true:warning
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async
# Code-block preferences
csharp_prefer_braces = false:suggestion
csharp_prefer_simple_using_statement = true
# Expression-level preferences
csharp_prefer_simple_default_expression = true:warning
csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_inlined_variable_declaration = true:warning
csharp_style_pattern_local_over_anonymous_function = true:warning
csharp_style_prefer_index_operator = true
csharp_style_prefer_range_operator = true
csharp_style_throw_expression = false:warning
csharp_style_unused_value_assignment_preference = discard_variable:silent
csharp_style_unused_value_expression_statement_preference = discard_variable
# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:error
#### C# Formatting Rules ####
# New line preferences
csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true
# Indentation preferences
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_case_contents_when_block = false
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true
# Space preferences
csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = ignore
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
#### Naming styles ####
# Naming rules
dotnet_naming_rule.interface_should_be_begins_with_i.severity = error
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.private_static_readonly_fields_convention.severity = error
+dotnet_naming_rule.private_static_readonly_fields_convention.symbols = private_static_fields_readonly
+dotnet_naming_rule.private_static_readonly_fields_convention.style = private_static_camel_case
+
dotnet_naming_rule.private_static_fields_convention.severity = error
dotnet_naming_rule.private_static_fields_convention.symbols = private_static_field_props
dotnet_naming_rule.private_static_fields_convention.style = private_static_camel_case
dotnet_naming_rule.readonly.severity = error
dotnet_naming_rule.readonly.symbols = readonly
dotnet_naming_rule.readonly.style = underscore_prefixed_camel_case
dotnet_naming_rule.private_field_should_be_underscore_prefixed_camel_case.severity = error
dotnet_naming_rule.private_field_should_be_underscore_prefixed_camel_case.symbols = private_fields
dotnet_naming_rule.private_field_should_be_underscore_prefixed_camel_case.style = underscore_prefixed_camel_case
dotnet_naming_rule.types_should_be_pascal_case.severity = error
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
dotnet_naming_rule.const_fields_should_be_all_upper.severity = error
dotnet_naming_rule.const_fields_should_be_all_upper.symbols = const_fields
dotnet_naming_rule.const_fields_should_be_all_upper.style = constant_style
dotnet_naming_rule.constants_should_be_upper_case.severity = error
dotnet_naming_rule.constants_should_be_upper_case.symbols = constants
dotnet_naming_rule.constants_should_be_upper_case.style = constant_style
dotnet_naming_rule.private_props_not_allowed.severity = error
dotnet_naming_rule.private_props_not_allowed.symbols = private_prop
dotnet_naming_rule.private_props_not_allowed.style = constant_style
# 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.private_static_fields_readonly.applicable_kinds = field
+dotnet_naming_symbols.private_static_fields_readonly.applicable_accessibilities = private
+dotnet_naming_symbols.private_static_fields_readonly.required_modifiers = static, readonly
+
dotnet_naming_symbols.private_static_field_props.applicable_kinds = field, property
dotnet_naming_symbols.private_static_field_props.applicable_accessibilities = private
dotnet_naming_symbols.private_static_field_props.required_modifiers = static
dotnet_naming_symbols.private_prop.applicable_kinds = property
dotnet_naming_symbols.private_prop.applicable_accessibilities = private
dotnet_naming_symbols.private_prop.required_modifiers =
dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const
dotnet_naming_symbols.const_fields.applicable_kinds = field, property
dotnet_naming_symbols.const_fields.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.const_fields.required_modifiers = const
dotnet_naming_symbols.readonly.applicable_kinds = field, property
dotnet_naming_symbols.readonly.applicable_accessibilities = private
dotnet_naming_symbols.readonly.required_modifiers = readonly
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private, private_protected
dotnet_naming_symbols.private_fields.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 =
# Naming styles
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.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.underscore_prefixed_camel_case.required_prefix = _
dotnet_naming_style.underscore_prefixed_camel_case.required_suffix =
dotnet_naming_style.underscore_prefixed_camel_case.word_separator =
dotnet_naming_style.underscore_prefixed_camel_case.capitalization = camel_case
dotnet_naming_style.private_static_camel_case.required_prefix = s_
dotnet_naming_style.private_static_camel_case.capitalization = camel_case
dotnet_naming_style.constant_style.required_prefix =
dotnet_naming_style.constant_style.required_suffix =
dotnet_naming_style.constant_style.word_separator = _
dotnet_naming_style.constant_style.capitalization = all_upper
diff --git a/DisCatSharp/Logging/DefaultLogger.cs b/DisCatSharp/Logging/DefaultLogger.cs
index 0994f996b..2584cd6ae 100644
--- a/DisCatSharp/Logging/DefaultLogger.cs
+++ b/DisCatSharp/Logging/DefaultLogger.cs
@@ -1,148 +1,148 @@
// This file is part of the DisCatSharp project, based off DSharpPlus.
//
// Copyright (c) 2021 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using Microsoft.Extensions.Logging;
namespace DisCatSharp
{
///
/// Represents a default logger.
///
public class DefaultLogger : ILogger
{
- private static readonly object _lock = new();
+ private static readonly object s_lock = new();
///
/// Gets the minimum log level.
///
private readonly LogLevel _minimumLevel;
///
/// Gets the timestamp format.
///
private readonly string _timestampFormat;
///
/// Initializes a new instance of the class.
///
/// The client.
internal DefaultLogger(BaseDiscordClient client)
: this(client.Configuration.MinimumLogLevel, client.Configuration.LogTimestampFormat)
{ }
///
/// Initializes a new instance of the class.
///
/// The min level.
/// The timestamp format.
internal DefaultLogger(LogLevel minLevel = LogLevel.Information, string timestampFormat = "yyyy-MM-dd HH:mm:ss zzz")
{
this._minimumLevel = minLevel;
this._timestampFormat = timestampFormat;
}
///
/// Logs an event.
///
/// The log level.
/// The event id.
/// The state.
/// The exception.
/// The formatter.
public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter)
{
if (!this.IsEnabled(logLevel))
return;
- lock (_lock)
+ lock (s_lock)
{
var ename = eventId.Name;
ename = ename?.Length > 12 ? ename?[..12] : ename;
Console.Write($"[{DateTimeOffset.Now.ToString(this._timestampFormat)}] [{eventId.Id,-4}/{ename,-12}] ");
switch (logLevel)
{
case LogLevel.Trace:
Console.ForegroundColor = ConsoleColor.Gray;
break;
case LogLevel.Debug:
Console.ForegroundColor = ConsoleColor.DarkMagenta;
break;
case LogLevel.Information:
Console.ForegroundColor = ConsoleColor.DarkCyan;
break;
case LogLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
case LogLevel.Critical:
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.Black;
break;
}
Console.Write(logLevel switch
{
LogLevel.Trace => "[Trace] ",
LogLevel.Debug => "[Debug] ",
LogLevel.Information => "[Info ] ",
LogLevel.Warning => "[Warn ] ",
LogLevel.Error => "[Error] ",
LogLevel.Critical => "[Crit ]",
LogLevel.None => "[None ] ",
_ => "[?????] "
});
Console.ResetColor();
//The foreground color is off.
if (logLevel == LogLevel.Critical)
Console.Write(" ");
var message = formatter(state, exception);
Console.WriteLine(message);
if (exception != null)
Console.WriteLine(exception);
}
}
///
/// Whether the logger is enabled.
///
/// The log level.
public bool IsEnabled(LogLevel logLevel)
=> logLevel >= this._minimumLevel;
///
/// Begins the scope.
///
/// The state.
/// An IDisposable.
public IDisposable BeginScope(TState state) => throw new NotImplementedException();
}
}