-
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.
Cherry pick branch 'genexuslabs:LoggingAPIImpl_Update' into beta
- Loading branch information
1 parent
de7565a
commit a7acebd
Showing
8 changed files
with
446 additions
and
16 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
48 changes: 48 additions & 0 deletions
48
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,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)); | ||
} | ||
|
||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...tcore/Providers/Logging/GeneXus.Log.Azure.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,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); | ||
} | ||
|
||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ders/Logging/GeneXus.Log.Azure.AzureAppInsights/GeneXus.Log.Azure.AzureAppInsights.csproj
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 @@ | ||
<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> |
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.