-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logging implementation update (#871)
- Loading branch information
Showing
179 changed files
with
1,484 additions
and
669 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
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 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 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 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 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 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
99 changes: 99 additions & 0 deletions
99
.../dotnetcore/GxClasses/Services/LogService/AzureAppInsights/AzureAppInsightsLogProvider.cs
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,99 @@ | ||
using System; | ||
using Azure.Monitor.OpenTelemetry.Exporter; | ||
using Microsoft.Extensions.Logging; | ||
using OpenTelemetry.Logs; | ||
|
||
namespace GeneXus.Services.Log | ||
{ | ||
public class AzureAppInsightsLogProvider : ILoggerFactory | ||
{ | ||
private static string APPLICATIONINSIGHTS_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING"; | ||
private const string LOG_LEVEL_ENVVAR = "GX_LOG_LEVEL"; | ||
public static ILoggerFactory loggerFactory; | ||
|
||
public static ILoggerFactory GetAzureMonitorLoggerFactory() | ||
{ | ||
string appInsightsConnection = Environment.GetEnvironmentVariable(APPLICATIONINSIGHTS_CONNECTION_STRING); | ||
try | ||
{ | ||
|
||
if (appInsightsConnection != null) | ||
{ | ||
string loglevelvalue = Environment.GetEnvironmentVariable(LOG_LEVEL_ENVVAR); | ||
LogLevel loglevel = LogLevel.Information; | ||
if (!string.IsNullOrEmpty(loglevelvalue)) | ||
{ | ||
Enum.TryParse<LogLevel>(loglevelvalue, out loglevel); | ||
} | ||
loggerFactory = LoggerFactory.Create(builder => | ||
{ | ||
builder.AddOpenTelemetry(options => | ||
{ | ||
options.AddAzureMonitorLogExporter(o => o.ConnectionString = appInsightsConnection); | ||
options.AddConsoleExporter(); | ||
}).SetMinimumLevel(loglevel); | ||
}); | ||
} | ||
else | ||
{ | ||
throw new ArgumentNullException(APPLICATIONINSIGHTS_CONNECTION_STRING, "Opentelemetry Provider is Azure Monitor. Application Insight Log could not be initialized due to missing APPLICATIONINSIGHTS_CONNECTION_STRING environment variable."); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
|
||
return loggerFactory; | ||
} | ||
|
||
public static ILoggerFactory GetLoggerFactory() | ||
{ | ||
string appInsightsConnection = Environment.GetEnvironmentVariable(APPLICATIONINSIGHTS_CONNECTION_STRING); | ||
try | ||
{ | ||
|
||
if (appInsightsConnection != null) | ||
{ | ||
string loglevelvalue = Environment.GetEnvironmentVariable(LOG_LEVEL_ENVVAR); | ||
LogLevel loglevel = LogLevel.Information; | ||
if (!string.IsNullOrEmpty(loglevelvalue)) | ||
{ | ||
Enum.TryParse<LogLevel>(loglevelvalue, out loglevel); | ||
} | ||
loggerFactory = LoggerFactory.Create(builder => builder.AddApplicationInsights( | ||
|
||
configureTelemetryConfiguration: (config) => | ||
config.ConnectionString = appInsightsConnection, | ||
configureApplicationInsightsLoggerOptions: (options) => { } | ||
).SetMinimumLevel(loglevel) | ||
); | ||
} | ||
else | ||
{ | ||
throw new ArgumentNullException(APPLICATIONINSIGHTS_CONNECTION_STRING, "LogOutput is Application Insights. Application Insight Log could not be initialized due to missing APPLICATIONINSIGHTS_CONNECTION_STRING environment variable."); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw ex; | ||
} | ||
|
||
return loggerFactory; | ||
} | ||
|
||
public void AddProvider(ILoggerProvider provider) | ||
{ | ||
loggerFactory.AddProvider(provider); | ||
} | ||
public void Dispose() | ||
{ | ||
loggerFactory.Dispose(); | ||
} | ||
public ILogger CreateLogger(string name) | ||
{ | ||
return loggerFactory.CreateLogger(name); | ||
} | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
dotnet/src/dotnetcore/GxClasses/Services/LogService/GXLogService.cs
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,23 @@ | ||
using GeneXus.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace GeneXus.Services.Log | ||
{ | ||
public static class GXLogService | ||
{ | ||
private static string AZURE_APPLICATION_INSIGHTS_LOG = "AZUREAPPLICATIONINSIGHTS"; | ||
const string OTEL_AZUREMONITOR_EXPORTER = "OTEL_AZUREMONITOR_EXPORTER"; | ||
const string LOG_OUTPUT = "LOG_OUTPUT"; | ||
public static ILoggerFactory GetLogFactory() | ||
{ | ||
if (Config.GetValueOf(LOG_OUTPUT, out string logProvider)) | ||
{ | ||
if (logProvider == OTEL_AZUREMONITOR_EXPORTER) | ||
return AzureAppInsightsLogProvider.GetAzureMonitorLoggerFactory(); | ||
else if (logProvider == AZURE_APPLICATION_INSIGHTS_LOG) | ||
return AzureAppInsightsLogProvider.GetLoggerFactory(); | ||
} | ||
return null; | ||
} | ||
} | ||
} |
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 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 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
Oops, something went wrong.