diff --git a/src/BlazorApplicationInsights/Logging/ApplicationInsightsLogger.cs b/src/BlazorApplicationInsights/Logging/ApplicationInsightsLogger.cs
index ce029aa..a9cd81b 100644
--- a/src/BlazorApplicationInsights/Logging/ApplicationInsightsLogger.cs
+++ b/src/BlazorApplicationInsights/Logging/ApplicationInsightsLogger.cs
@@ -44,6 +44,9 @@ public ApplicationInsightsLogger(string? categoryName, IApplicationInsights appl
/// Include scope information in CustomDimensions
public bool IncludeScopes { get; set; }
+ /// Min LogLevel to write to app insights
+ public LogLevel MinLogLevel { get; set; }
+
///
/// Callback that will be called before customDimensions are set
/// This allows enriching customDimensions with values that should apply to all log lines
@@ -86,7 +89,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except
}
///
- public bool IsEnabled(LogLevel logLevel) => logLevel != LogLevel.None;
+ public bool IsEnabled(LogLevel logLevel) => this.MinLogLevel <= logLevel && logLevel != LogLevel.None;
///
public IDisposable BeginScope(TState state) => ScopeProvider.Push(state);
diff --git a/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerOptions.cs b/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerOptions.cs
index d5596e9..3571353 100644
--- a/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerOptions.cs
+++ b/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerOptions.cs
@@ -3,6 +3,7 @@
using System.ComponentModel;
using System.Text.Json.Serialization;
using JetBrains.Annotations;
+using Microsoft.Extensions.Logging;
// ReSharper disable once CheckNamespace
namespace BlazorApplicationInsights;
@@ -19,8 +20,12 @@ public class ApplicationInsightsLoggerOptions
/// Include scope information in customDimensions
public bool IncludeScopes { get; set; } = true;
+ /// Min LogLevel to write to app insights defaults to Trace aka Verbose
+ public LogLevel MinLogLevel { get; set; } = LogLevel.Trace;
+
[JsonIgnore]
[Obsolete("Not part of the stable API")]
[EditorBrowsable(EditorBrowsableState.Never)]
+
public Action>? EnrichCallback { get; set; }
}
\ No newline at end of file
diff --git a/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerProvider.cs b/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerProvider.cs
index e3448f8..09616d3 100644
--- a/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerProvider.cs
+++ b/src/BlazorApplicationInsights/Logging/ApplicationInsightsLoggerProvider.cs
@@ -69,6 +69,7 @@ private ApplicationInsightsLogger CreateLoggerInstance(string categoryName)
return new ApplicationInsightsLogger(categoryName, _applicationInsights)
{
ScopeProvider = GetScopeProvider(),
+ MinLogLevel = _options.MinLogLevel,
IncludeScopes = _options.IncludeScopes,
IncludeCategoryName = _options.IncludeCategoryName,
@@ -98,6 +99,7 @@ private void ReloadOptions(ApplicationInsightsLoggerOptions options)
logger.ScopeProvider = scopeProvider;
logger.IncludeCategoryName = options.IncludeCategoryName;
logger.IncludeScopes = options.IncludeScopes;
+ logger.MinLogLevel = options.MinLogLevel;
#pragma warning disable 618
logger.EnrichmentCallback = _enrichmentCallback;