Skip to content

Commit

Permalink
Implementation for NET to use Microsoft.Extensions.Logging API.
Browse files Browse the repository at this point in the history
Add impl for Application Insights logging.
  • Loading branch information
sjuarezgx committed Sep 24, 2023
1 parent 1e13260 commit 9e6c779
Show file tree
Hide file tree
Showing 139 changed files with 954 additions and 650 deletions.
10 changes: 0 additions & 10 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXAzureEventGrid", "src\dot
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCoreAttackMitigationTest", "test\DotNetCoreAttackMitigationTest\DotNetCoreAttackMitigationTest.csproj", "{2D615969-53E2-4B77-9A9A-75C33865CF76}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gxlogging", "gxlogging", "{AA04A8A9-3CBD-431D-9711-C4D481E4A1E5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneXus.Log.Azure.AzureAppInsights", "src\dotnetcore\Providers\Logging\GeneXus.Log.Azure.AzureAppInsights\GeneXus.Log.Azure.AzureAppInsights.csproj", "{6B28F942-D355-44A2-9C5D-92AF2D256A0D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -610,10 +606,6 @@ Global
{2D615969-53E2-4B77-9A9A-75C33865CF76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D615969-53E2-4B77-9A9A-75C33865CF76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D615969-53E2-4B77-9A9A-75C33865CF76}.Release|Any CPU.Build.0 = Release|Any CPU
{6B28F942-D355-44A2-9C5D-92AF2D256A0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B28F942-D355-44A2-9C5D-92AF2D256A0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B28F942-D355-44A2-9C5D-92AF2D256A0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B28F942-D355-44A2-9C5D-92AF2D256A0D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -733,8 +725,6 @@ Global
{5BBC75F0-E51A-4EBD-A628-92498D319B1D} = {4C43F2DA-59E5-46F5-B691-195449498555}
{7250CDB1-95C4-4822-B01B-3CBD73324CC9} = {30159B0F-BE61-4DB7-AC02-02851426BE4B}
{2D615969-53E2-4B77-9A9A-75C33865CF76} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}
{AA04A8A9-3CBD-431D-9711-C4D481E4A1E5} = {2261B65E-3757-4E5B-9DCD-EAE8D1E236A3}
{6B28F942-D355-44A2-9C5D-92AF2D256A0D} = {AA04A8A9-3CBD-431D-9711-C4D481E4A1E5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}
Expand Down
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 @@ -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<GeneXus.HttpHandlerFactory.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
2 changes: 1 addition & 1 deletion dotnet/src/dotnetcore/GxClasses/GxClasses.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\Encryption.cs" Link="Helpers\Encryption.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\EnvVarReader.cs" Link="Helpers\EnvVarReader.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\GXFileWatcher.cs" Link="Helpers\GXFileWatcher.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\GXLogging.cs" Link="Helpers\GXLogging.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\GxObjectProperties.cs" Link="Helpers\GxObjectProperties.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\GXRestAPIClient.cs" Link="Helpers\GXRestAPIClient.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Model\GXBaseObject.cs" Link="Model\GXBaseObject.cs" />
Expand All @@ -78,6 +77,7 @@
<Compile Include="..\..\dotnetframework\GxClasses\Domain\GxHttpClient.cs" Link="Domain\GxHttpClient.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Core\Web\GxHttpServer.cs" Link="Core\Web\GxHttpServer.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Domain\GxLocations.cs" Link="Domain\GxLocations.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\GXLogging.cs" Link="Helpers\GXLogging.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Helpers\GXMetadata.cs" Link="Helpers\GXMetadata.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Printer\GxPrinter.cs" Link="Printer\GxPrinter.cs" />
<Compile Include="..\..\dotnetframework\GxClasses\Model\gxproc.cs" Link="Model\gxproc.cs" />
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
@@ -1,24 +1,23 @@
using System;
using GeneXus.Services;
using GeneXus.Services.Log;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Configuration;

namespace GeneXus.Log.Azure
namespace GeneXus.Services.Log
{
public class AzureAppInsightsLogProvider : IGXLogProvider
public class AzureAppInsightsLogProvider : ILoggerFactory
{
private static string APPLICATIONINSIGHTS_CONNECTION_STRING = "APPLICATIONINSIGHTS_CONNECTION_STRING";

public static ILoggerFactory loggerFactory;

public AzureAppInsightsLogProvider(GXService s) { }
public ILoggerFactory GetLoggerFactory()

public static ILoggerFactory GetLoggerFactory()
{
string appInsightsConnection = Environment.GetEnvironmentVariable(APPLICATIONINSIGHTS_CONNECTION_STRING);
if (appInsightsConnection != null) {
loggerFactory = LoggerFactory.Create(builder => builder.AddApplicationInsights(

configureTelemetryConfiguration: (config) =>
//config.SetAzureTokenCredential
config.ConnectionString = appInsightsConnection,
configureApplicationInsightsLoggerOptions: (options) => { }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,25 @@
using System;
using GeneXus.Application;
using GxClasses.Helpers;
using GeneXus.Configuration;
using Microsoft.Extensions.Logging;

namespace GeneXus.Services.Log
{
public interface IGXLogProvider : ILoggerFactory
{
ILoggerFactory GetLoggerFactory();
}

public static class GXLogService
{
private static string LOG_SERVICE = "Log";

private static string AZURE_APPLICATION_INSIGHTS_LOG = "AZUREAPPLICATIONINSIGHTS";
private const string LOG_OUTPUT_ENVVAR = "GX_LOG_OUTPUT";
public static ILoggerFactory GetLogFactory()
{
IGXLogProvider gxLogProvider = null;
GXService providerService = GXServices.Instance?.Get(LOG_SERVICE);
string logoutput = Environment.GetEnvironmentVariable(LOG_OUTPUT_ENVVAR);
if (logoutput == null) {

if (providerService != null)
{
try
{
#if !NETCORE
Type type = Type.GetType(providerService.ClassName, true, true);
#else
Type type = AssemblyLoader.GetType(providerService.ClassName);
#endif
gxLogProvider = (IGXLogProvider)Activator.CreateInstance(type, new object[] { providerService });
return gxLogProvider.GetLoggerFactory();
}
catch (Exception e)
{
throw e;
}
Config.GetValueOf("LOG_OUTPUT", out string logProvider);
logoutput = logProvider;
}
if (logoutput == AZURE_APPLICATION_INSIGHTS_LOG)
return GeneXus.Services.Log.AzureAppInsightsLogProvider.GetLoggerFactory();
else
{
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
Loading

0 comments on commit 9e6c779

Please sign in to comment.