Skip to content

Commit 4bcf3b5

Browse files
committed
Set minimum log level by reading env var.
1 parent 066dbab commit 4bcf3b5

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

dotnet/src/dotnetcore/GxClasses/Services/LogService/AzureAppInsights/AzureAppInsightsLogProvider.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace GeneXus.Services.Log
88
public class AzureAppInsightsLogProvider : ILoggerFactory
99
{
1010
private static string APPLICATIONINSIGHTS_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING";
11+
private const string LOG_LEVEL_ENVVAR = "GX_LOG_LEVEL";
1112
public static ILoggerFactory loggerFactory;
1213

1314
public static ILoggerFactory GetAzureMonitorLoggerFactory()
@@ -18,13 +19,19 @@ public static ILoggerFactory GetAzureMonitorLoggerFactory()
1819

1920
if (appInsightsConnection != null)
2021
{
22+
string loglevelvalue = Environment.GetEnvironmentVariable(LOG_LEVEL_ENVVAR);
23+
LogLevel loglevel = LogLevel.Information;
24+
if (!string.IsNullOrEmpty(loglevelvalue))
25+
{
26+
Enum.TryParse<LogLevel>(loglevelvalue, out loglevel);
27+
}
2128
loggerFactory = LoggerFactory.Create(builder =>
2229
{
2330
builder.AddOpenTelemetry(options =>
2431
{
2532
options.AddAzureMonitorLogExporter(o => o.ConnectionString = appInsightsConnection);
2633
options.AddConsoleExporter();
27-
});
34+
}).SetMinimumLevel(loglevel);
2835
});
2936
}
3037
else
@@ -48,12 +55,18 @@ public static ILoggerFactory GetLoggerFactory()
4855

4956
if (appInsightsConnection != null)
5057
{
58+
string loglevelvalue = Environment.GetEnvironmentVariable(LOG_LEVEL_ENVVAR);
59+
LogLevel loglevel = LogLevel.Information;
60+
if (!string.IsNullOrEmpty(loglevelvalue))
61+
{
62+
Enum.TryParse<LogLevel>(loglevelvalue, out loglevel);
63+
}
5164
loggerFactory = LoggerFactory.Create(builder => builder.AddApplicationInsights(
5265

5366
configureTelemetryConfiguration: (config) =>
5467
config.ConnectionString = appInsightsConnection,
5568
configureApplicationInsightsLoggerOptions: (options) => { }
56-
)
69+
).SetMinimumLevel(loglevel)
5770
);
5871
}
5972
else

0 commit comments

Comments
 (0)