Skip to content

Commit f761a2d

Browse files
Improve LogLevel checking
1 parent b493ca6 commit f761a2d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT license. See License.txt in the project root for license information.
3+
4+
namespace Microsoft.CodeAnalysis.Razor.Logging;
5+
6+
internal static class LogLevelExtensions
7+
{
8+
public static bool IsAtLeast(this LogLevel target, LogLevel logLevel)
9+
{
10+
return target >= logLevel && target != LogLevel.None;
11+
}
12+
13+
public static bool IsAtMost(this LogLevel target, LogLevel logLevel)
14+
{
15+
return target <= logLevel || target == LogLevel.None;
16+
}
17+
}

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/ActivityLogLoggerProvider.Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private sealed class Logger(RazorActivityLog activityLog, string categoryName) :
1616
private readonly string _categoryName = categoryName;
1717

1818
public bool IsEnabled(LogLevel logLevel)
19-
=> logLevel is LogLevel.Warning or LogLevel.Error or LogLevel.Critical;
19+
=> logLevel.IsAtLeast(LogLevel.Warning);
2020

2121
public void Log(LogLevel logLevel, string message, Exception? exception)
2222
{

0 commit comments

Comments
 (0)