Skip to content

Commit

Permalink
Logging implementation update (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuarezgx authored Nov 1, 2023
1 parent a868e1c commit a849d02
Show file tree
Hide file tree
Showing 179 changed files with 1,484 additions and 669 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using GeneXus.Cache;
using GeneXus.Data.Cosmos;
using GeneXus.Data.NTier.CosmosDB;
using log4net;
using Microsoft.Azure.Cosmos;

namespace GeneXus.Data.NTier
Expand Down Expand Up @@ -65,7 +64,7 @@ public class CosmosDBConnection : ServiceConnection
//Options not supported by the spec yet
//private const string DISTINCT = "DISTINCT";

static readonly ILog logger = log4net.LogManager.GetLogger(typeof(CosmosDBConnection));
static readonly IGXLogger logger = GXLoggerFactory.GetLogger<CosmosDBConnection>();
public override string ConnectionString
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using GeneXus.Cache;
using GeneXus.Data.NTier;
using GeneXus.Data.NTier.CosmosDB;
using log4net;
using Microsoft.Azure.Cosmos;
using Newtonsoft.Json;

Expand All @@ -27,7 +26,7 @@ public class CosmosDBDataReader : IDataReader
private int ItemCount;
private List<Dictionary<string, object>> Items = null;

static readonly ILog logger = log4net.LogManager.GetLogger(typeof(CosmosDBDataReader));
static readonly IGXLogger logger = GXLoggerFactory.GetLogger<CosmosDBDataReader>();
private void CheckCurrentPosition()
{
if (m_currentEntry == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.IO;
using System.Threading.Tasks;
using GeneXus.Data.Cosmos;
using log4net;
using Microsoft.Azure.Cosmos;
using Newtonsoft.Json;

Expand All @@ -14,7 +13,7 @@ public class RequestWrapper
private readonly Container m_container;
private readonly CosmosClient m_cosmosClient;
private readonly QueryDefinition m_queryDefinition;
static readonly ILog logger = log4net.LogManager.GetLogger(typeof(RequestWrapper));
static readonly IGXLogger logger = GXLoggerFactory.GetLogger<RequestWrapper>();
public string idValue { get; set; }
public object partitionKeyValue { get; set; }
public bool queryByPK { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.31.0" />
<PackageReference Include="Azure.Core" Version="1.35.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.36.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="GeneXus.Odata.Client" Version="5.2.3.8" />
<PackageReference Include="log4net" Version="2.0.15" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GxClasses\GxClasses.csproj" />
Expand Down
3 changes: 2 additions & 1 deletion dotnet/src/dotnetcore/GxClasses.Web/GxClasses.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace GxClasses.Web.Middleware
internal class GXRouting : IGXRouting
{

static readonly ILog log = log4net.LogManager.GetLogger(typeof(IGXRouting));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<IGXRouting>();

public static string VirtualPath = string.Empty;
public static string LocalPath = Directory.GetCurrentDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class BaseUrls

public class HandlerFactory
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(GeneXus.HttpHandlerFactory.HandlerFactory));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<HandlerFactory>();
private string _basePath;
static Dictionary<string, Type> _aspxObjects = new Dictionary<string, Type>(){
{"gxoauthlogout",typeof(GXOAuthLogout)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace GeneXus.Http.WebSocket
{
public class WSHandler: WebSocketHandler, IGXWebSocketAsync
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(WSHandler));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<WSHandler>();
private const string GX_NOTIFICATIONINFO_NAME = "GeneXus.Core.genexus.server.SdtNotificationInfo";
protected static WebSocketConnectionManager WebSocketConnectionManager = new WebSocketConnectionManager();

Expand Down
14 changes: 6 additions & 8 deletions dotnet/src/dotnetcore/GxClasses/Domain/GXXmlReadWrite.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using System;
using System.Xml;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Net;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.XPath;
using System.Xml.Xsl;
using GeneXus.Application;
using GeneXus.Http.Client;
using GeneXus.Http.Server;
using GeneXus.Utils;
using log4net;

using System.Xml.Xsl;
using System.Xml.XPath;

namespace GeneXus.XML
{
Expand Down Expand Up @@ -1887,7 +1885,7 @@ public void Dispose()

public class GXXMLWriter: IDisposable
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(GXXMLWriter));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<GXXMLWriter>();
private XmlTextWriter writer;

private short errorCode;
Expand Down
8 changes: 7 additions & 1 deletion dotnet/src/dotnetcore/GxClasses/GxClasses.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
Expand Down Expand Up @@ -157,6 +157,12 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.21.0" PrivateAssets="ALL" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.0.0-beta.13" NoWarn="NU5104" PrivateAssets="All" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.5.1" PrivateAssets="All" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="7.0.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.7.0" />
<PackageReference Include="MySqlConnector" Version="2.2.3" />
<PackageReference Include="NetTopologySuite" Version="2.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/dotnetcore/GxClasses/Helpers/GXGeographyCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ internal static object STRingN(object instance, int i)
[DataContract]
public class Geospatial : IGeographicNative
{
static readonly ILog log = log4net.LogManager.GetLogger(typeof(GeneXus.Utils.Geospatial));
static readonly IGXLogger log = GXLoggerFactory.GetLogger<GeneXus.Utils.Geospatial>();

internal const string EMPTY_GEOMETRY = "GEOMETRYCOLLECTION EMPTY";
const string EMPTY_GEOGRAPHY = "GEOGRAPHY EMPTY";
Expand Down
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);
}

}
}
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public interface IOpenTelemetryProvider

public static class OpenTelemetryService
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(OpenTelemetryService));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

private static string OPENTELEMETRY_SERVICE = "Observability";
public static string GX_ACTIVITY_SOURCE_NAME = "GeneXus.Tracing";

Expand Down Expand Up @@ -49,7 +50,7 @@ internal static void Setup(Microsoft.Extensions.DependencyInjection.IServiceColl
bool started = provider.InstrumentAspNetCoreApplication(services);
if (started)
{
log.Info("OpenTelemetry instrumentation started");
GXLogging.Info(log, "OpenTelemetry instrumentation started");
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/dotnetcore/GxClasses/Services/ServiceSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GeneXus.Services.Common
{
public class ServiceSettingsReader
{
static readonly ILog logger = log4net.LogManager.GetLogger(typeof(ServiceSettingsReader));
static readonly IGXLogger logger = GXLoggerFactory.GetLogger<ServiceSettingsReader>();

internal GXService service;
public string serviceNameResolver { get; }
Expand All @@ -25,7 +25,7 @@ public string GetEncryptedPropertyValue(string propertyName)
if (value == null)
{
String errorMessage = String.Format($"Service configuration error - Property name {ResolvePropertyName(propertyName)} must be defined");
logger.Fatal(errorMessage);
GXLogging.Critical(logger, errorMessage);
throw new Exception(errorMessage);
}
return value;
Expand All @@ -45,7 +45,7 @@ public string GetEncryptedPropertyValue(string propertyName, string defaultValue
}
catch (Exception)
{
logger.Warn($"Could not decrypt property name: {ResolvePropertyName(propertyName)}");
GXLogging.Warn(logger, $"Could not decrypt property name: {ResolvePropertyName(propertyName)}");
}
}
return value;
Expand All @@ -57,7 +57,7 @@ public string GetPropertyValue(string propertyName)
if (value == null)
{
String errorMessage = String.Format($"Service configuration error - Property name {ResolvePropertyName(propertyName)} must be defined");
logger.Fatal(errorMessage);
GXLogging.Critical(logger, errorMessage);
throw new Exception(errorMessage);
}
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace GeneXus.Services
{
public class GXSessionServiceFactory
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(GXSessionServiceFactory));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<GXSessionServiceFactory>();

static string REDIS = "REDIS";
static string DATABASE = "DATABASE";
public static ISessionService GetProvider()
Expand Down Expand Up @@ -58,7 +59,7 @@ public static ISessionService GetProvider()
}
public class GxRedisSession : ISessionService
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(GxRedisSession));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<GxRedisSession>();
internal static string SESSION_ADDRESS = "SESSION_PROVIDER_ADDRESS";
internal static string SESSION_INSTANCE = "SESSION_PROVIDER_INSTANCE_NAME";
internal static string SESSION_PASSWORD = "SESSION_PROVIDER_PASSWORD";
Expand Down Expand Up @@ -108,7 +109,7 @@ public GxRedisSession(string host, string password, string instanceName, int ses
}
public class GxDatabaseSession : ISessionService
{
private static readonly ILog log = log4net.LogManager.GetLogger(typeof(GxDatabaseSession));
private static readonly IGXLogger log = GXLoggerFactory.GetLogger<GxDatabaseSession>();
internal static string SESSION_ADDRESS = "SESSION_PROVIDER_ADDRESS";
internal static string SESSION_PASSWORD = "SESSION_PROVIDER_PASSWORD";
internal static string SESSION_SCHEMA = "SESSION_PROVIDER_SCHEMA";
Expand Down
1 change: 0 additions & 1 deletion dotnet/src/dotnetcore/GxExcel/GxExcel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<ItemGroup>
<PackageReference Include="EPPlus" Version="4.5.3.2" />
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="6.0.3" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion dotnet/src/dotnetcore/GxMail/GxMail.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="log4net" Version="2.0.15" />
<PackageReference Include="MailKit" Version="3.1.1" />
<PackageReference Include="Microsoft.Exchange.WebServices" Version="2.2.0" />
<PackageReference Include="MimeKit" Version="3.1.1" />
Expand Down
Loading

0 comments on commit a849d02

Please sign in to comment.