Skip to content

Commit

Permalink
Cherry pick branch 'genexuslabs:LoggingAPIImpl_Update' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
sjuarezgx authored and genexusbot committed Sep 3, 2023
1 parent de7565a commit a7acebd
Show file tree
Hide file tree
Showing 8 changed files with 446 additions and 16 deletions.
13 changes: 13 additions & 0 deletions dotnet/DotNetStandardClasses.sln
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXAzureStorage", "src\dotnetcore\Providers\Storage\GXAzureStorage\GXAzureStorage.csproj", "{BF72FAF5-3A7C-41B6-A27F-9BE049290356}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC}"
ProjectSection(SolutionItems) = preProject
src\dotnetcore\GxNetCoreStartup\Startup.cs = src\dotnetcore\GxNetCoreStartup\Startup.cs
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GxEncryptCMD", "src\dotnetframework\GxEncryptCMD\GxEncryptCMD.csproj", "{E2CC404A-3AE4-4CE9-84DC-0EA6078F69E3}"
EndProject
Expand Down Expand Up @@ -255,6 +258,10 @@ 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 @@ -613,6 +620,10 @@ 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 @@ -729,6 +740,8 @@ 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
2 changes: 2 additions & 0 deletions dotnet/src/dotnetcore/GxClasses.Web/GxClasses.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

<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
2 changes: 2 additions & 0 deletions dotnet/src/dotnetcore/GxClasses/GxClasses.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@
<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.Win32.Registry" Version="4.7.0" />
<PackageReference Include="MySqlConnector" Version="2.2.3" />
<PackageReference Include="NetTopologySuite" Version="2.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using GeneXus.Application;
using GxClasses.Helpers;
using Microsoft.Extensions.Logging;

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

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

public static ILoggerFactory GetLogFactory()
{
IGXLogProvider gxLogProvider = null;
GXService providerService = GXServices.Instance?.Get(LOG_SERVICE);

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;
}
}
else
{
string log4net_config = GxContext.IsHttpContext ? "log.config" : "log.console.config";
Log4NetProvider log4NetProvider = new Log4NetProvider(log4net_config);
return LoggerFactory.Create(builder => builder.AddProvider(log4NetProvider));
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using GeneXus.Services;
using GeneXus.Services.Log;
using Microsoft.Extensions.Logging;

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

public static ILoggerFactory loggerFactory;

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

configureTelemetryConfiguration: (config) =>
config.ConnectionString = appInsightsConnection,
configureApplicationInsightsLoggerOptions: (options) => { }
)
);

}
else
{
throw new ArgumentNullException("APPLICATIONINSIGHTS_CONNECTION_STRING","Application Insight Log could not be initialized due to missing APPLICATIONINSIGHTS_CONNECTION_STRING environment variable.");
}
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 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<DefineConstants>NETCORE;</DefineConstants>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SignAssembly>false</SignAssembly>
<AssemblyName>GeneXus.Log.Azure.AzureAppInsights</AssemblyName>
<PackageTags>Azure Application Insights Log GeneXus</PackageTags>
<PackageId>GeneXus.Log.Azure.AzureAppInsights</PackageId>
</PropertyGroup>

<ItemGroup>
<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" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\GxClasses\GxClasses.csproj" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions dotnet/src/dotnetframework/GxClasses/GxClasses.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
<PackageTags>Data Access</PackageTags>
<PackageId>GeneXus.Classes</PackageId>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\dotnetcore\GxClasses\Services\LogService\GXLogService.cs" Link="Services\GXLogService.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="GeneXus.NodaTime" Version="2.4.19.1" />
<PackageReference Include="ManagedFusion.Rewriter" Version="3.7.0" />
<PackageReference Include="Microsoft.AspNet.WebPages" Version="3.2.9" />
Expand Down
Loading

0 comments on commit a7acebd

Please sign in to comment.