Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging implementation update #871

Merged
merged 53 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
204d8f8
Logging implementation update
sjuarezgx Sep 3, 2023
495fbc6
Exclude new logging API for Net FW, use the previous one.
sjuarezgx Sep 6, 2023
c67e6f7
Enable MsExtensions Logging only for .NET.
claudiamurialdo Sep 6, 2023
53027ae
Add missing file.
claudiamurialdo Sep 6, 2023
014d979
Rename test.
claudiamurialdo Sep 6, 2023
1e13260
Make GXLoggerMsExtensions and GXLoggerLog4Net internals as they are n…
claudiamurialdo Sep 6, 2023
3c14450
Remove wrong .cs in .sln
claudiamurialdo Sep 11, 2023
9e6c779
Implementation for NET to use Microsoft.Extensions.Logging API.
sjuarezgx Sep 24, 2023
c2c9445
Merge branch 'LoggingAPIImpl_Update' of https://github.com/genexuslab…
sjuarezgx Sep 25, 2023
8ff31b0
Merge branch 'master' into LoggingAPIImpl_Update
sjuarezgx Sep 25, 2023
ac5bbca
fix merge error
sjuarezgx Sep 25, 2023
19c9467
Fix in previous merge which not included changes already released
sjuarezgx Sep 25, 2023
585b983
Fix unit test.
sjuarezgx Sep 26, 2023
78414ae
Fix case not working for reading appsettings.<env>.json
sjuarezgx Sep 26, 2023
8c9186b
Minor change to re-run tests
sjuarezgx Sep 26, 2023
9673496
Fix test failure.
sjuarezgx Sep 27, 2023
dceb034
Fix TestCouldNotLoadSystemDiagnosticsDiagnosticSource7_0_0_0 test.
claudiamurialdo Sep 27, 2023
acde512
Define environment variables exclusively for the current process.
claudiamurialdo Sep 27, 2023
72f2db5
Set environment variables earlier to enable the Startup program to re…
claudiamurialdo Sep 27, 2023
93bbf81
Support to use defaultAzureCredentials again.
sjuarezgx Sep 27, 2023
b0c5179
Do not distribute always ApplicationInsights dependencies.
sjuarezgx Sep 28, 2023
a0fa045
dummy commit
sjuarezgx Oct 17, 2023
b363c15
Merge branch 'master' into LoggingAPIImpl_Update
sjuarezgx Oct 17, 2023
f5abb1c
use new loggger factory
sjuarezgx Oct 18, 2023
3c9cec2
update to new new logger factory
sjuarezgx Oct 18, 2023
abab49c
Simplify class names.
claudiamurialdo Oct 18, 2023
aa055f4
Cyclic dependendy fixed using App insights logging
sjuarezgx Oct 19, 2023
a7e7f33
Use AzureMonitorLogExporter when Opentelemetry for Azure App Insights…
sjuarezgx Oct 22, 2023
d36ec7c
Do not need to set Logoutput to App Insights if Azure Opentelemetry i…
sjuarezgx Oct 22, 2023
2401c8b
skip tests to try to build the branch
sjuarezgx Oct 23, 2023
0393f33
Remove unnecessary public visibility from the GetLogger method.
claudiamurialdo Oct 23, 2023
5f0f2a5
Try to fix tests
sjuarezgx Oct 24, 2023
30e1024
Threads were locked when attempting to acquire a logger using GetLogg…
claudiamurialdo Oct 24, 2023
72cad9e
Eliminate the returns from config.get to allow the final trace lines …
claudiamurialdo Oct 24, 2023
69496bd
Set GXLoggerFactory._instance to a private access modifier.
claudiamurialdo Oct 24, 2023
bedb28e
Remove log initialization inside lock.
claudiamurialdo Oct 24, 2023
0732ffd
Ensure that services are loaded in the configuration, as logging depe…
claudiamurialdo Oct 24, 2023
42639bb
Added some constants.
claudiamurialdo Oct 24, 2023
550fb97
Restore AttackMitigation tests.
claudiamurialdo Oct 24, 2023
04a178a
Remove the dependency between gxservices.config and the logging confi…
claudiamurialdo Oct 24, 2023
b477aa0
Update libraries for some proyects that include Azure.Core as transit…
sjuarezgx Oct 25, 2023
3a1ad38
Add reference to Azure.Core 1.35 to projects.
sjuarezgx Oct 25, 2023
7428fcc
Extended the AssemblyResolve method to dynamically load assemblies ba…
claudiamurialdo Oct 25, 2023
5db72ec
Merge branch 'LoggingAPIImpl_Update' of https://github.com/genexuslab…
claudiamurialdo Oct 25, 2023
2dbf3fe
make exception message more clear when App Insights env variable is m…
sjuarezgx Oct 26, 2023
88c694e
Merge branch 'LoggingAPIImpl_Update' of https://github.com/genexuslab…
sjuarezgx Oct 26, 2023
57bb4d7
First must evaluate if it's Otel Azure Monitor. Besides, there was a …
sjuarezgx Oct 29, 2023
066dbab
dummy commit
sjuarezgx Oct 30, 2023
4bcf3b5
Set minimum log level by reading env var.
sjuarezgx Nov 1, 2023
a33caaa
Merge branch 'master' into LoggingAPIImpl_Update
sjuarezgx Nov 1, 2023
02a050e
The reference to the log4net package is no longer necessary for proje…
claudiamurialdo Nov 1, 2023
1a9a507
Added thread ID to the context properties of log4net as a workaround …
claudiamurialdo Nov 1, 2023
ce66577
Fix build error.
claudiamurialdo Nov 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
claudiamurialdo marked this conversation as resolved.
Show resolved Hide resolved
{
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