Skip to content

Commit

Permalink
Fix unit test.
Browse files Browse the repository at this point in the history
(cherry picked from commit 585b983)
  • Loading branch information
sjuarezgx committed Sep 26, 2023
1 parent 14c8d5d commit 0aa9f6d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 35 deletions.
1 change: 1 addition & 0 deletions dotnet/src/dotnetcore/GxClasses/GxClasses.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
</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" />
<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
@@ -1,6 +1,5 @@
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Configuration;

namespace GeneXus.Services.Log
{
Expand All @@ -17,7 +16,6 @@ public static ILoggerFactory GetLoggerFactory()
loggerFactory = LoggerFactory.Create(builder => builder.AddApplicationInsights(

configureTelemetryConfiguration: (config) =>
//config.SetAzureTokenCredential
config.ConnectionString = appInsightsConnection,
configureApplicationInsightsLoggerOptions: (options) => { }
)
Expand Down
11 changes: 3 additions & 8 deletions dotnet/src/dotnetcore/GxNetCoreStartup/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using GeneXus.Services.OpenTelemetry;
using GeneXus.Utils;
using GxClasses.Web.Middleware;
using log4net;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Antiforgery;
using Microsoft.AspNetCore.Builder;
Expand All @@ -36,7 +35,6 @@
using OpenTelemetry.Resources;
using StackExchange.Redis;


namespace GeneXus.Application
{
public class Program
Expand Down Expand Up @@ -171,6 +169,7 @@ public class Startup
{
public static bool IsHttpContext = InitializeHttpContext();
static readonly IGXLogger log = GXLoggerFactory.GetLogger<Startup>();

const long DEFAULT_MAX_FILE_UPLOAD_SIZE_BYTES = 528000000;
public static string VirtualPath = string.Empty;
public static string LocalPath = Directory.GetCurrentDirectory();
Expand All @@ -193,7 +192,6 @@ public class Startup
public List<string> servicesBase = new List<string>();

private GXRouting gxRouting;

static bool InitializeHttpContext()
{
GxContext.IsHttpContext = true;
Expand Down Expand Up @@ -348,11 +346,8 @@ private void ConfigureSessionService(IServiceCollection services, ISessionServic
public void Configure(IApplicationBuilder app, Microsoft.AspNetCore.Hosting.IHostingEnvironment env, ILoggerFactory loggerFactory)
{
string baseVirtualPath = string.IsNullOrEmpty(VirtualPath) ? VirtualPath : $"/{VirtualPath}";
Config.GetValueOf("LOG_OUTPUT", out string logProvider);
if (logProvider == "ASPNetTraceAppender" || logProvider == "ConsoleAppender" || logProvider == "EventLogAppender" || logProvider == "RollingFile")
{
LogConfiguration.SetupLog4Net();
}
LogConfiguration.SetupLog4Net();

var provider = new FileExtensionContentTypeProvider();
//mappings
provider.Mappings[".json"] = "application/json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ internal class LogConfiguration

public static void SetupLog4Net()
{
SetupLog4NetFromEnvironmentVariables();
Config.GetValueOf("LOG_OUTPUT", out string logProvider);
if (logProvider == "ASPNetTraceAppender" || logProvider == "ConsoleAppender" || logProvider == "EventLogAppender" || logProvider == "RollingFile")
{
SetupLog4NetFromEnvironmentVariables();
}
}

private static void SetupLog4NetFromEnvironmentVariables()
Expand Down
5 changes: 2 additions & 3 deletions dotnet/src/dotnetframework/GxClasses/Core/GXApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ internal class GxApplication
public class GxContext : IGxContext
{
private static IGXLogger log = null;
public static bool configurationLoaded = Config.configLoaded;
internal static bool configurationLoaded = Config.configLoaded;
internal static string GX_SPA_REQUEST_HEADER = "X-SPA-REQUEST";
internal static string GX_SPA_REDIRECT_URL = "X-SPA-REDIRECT-URL";
internal const string GXLanguage = "GXLanguage";
Expand Down Expand Up @@ -460,7 +460,7 @@ static IGXLogger Logger
{
get
{
if (configurationLoaded)
if (Config.configLoaded)
{
if (log == null)
{
Expand Down Expand Up @@ -1016,7 +1016,6 @@ private bool CheckFileExists(string fileName)
public void StatusMessage(string message)
{
StackFrame frame = new StackFrame(1);

IGXLogger statusLog = GXLoggerFactory.GetLogger(frame.GetMethod().DeclaringType.FullName);
GXLogging.Info(statusLog, message);
Console.WriteLine(message);
Expand Down
27 changes: 9 additions & 18 deletions dotnet/src/dotnetframework/GxClasses/Core/gxconfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Config
private static string configFileName;
public static string loadedConfigFile;
private static bool configLog = true;
public static bool configLoaded;
internal static bool configLoaded;
static NameValueCollection _config;
static ConcurrentDictionary<string, string> s_confMapping;
const string CONFMAPPING_FILE = "confmapping.json";
Expand Down Expand Up @@ -81,11 +81,7 @@ public static void ParseArgs(ref string[] args)
}

}
Config.GetValueOf("LOG_OUTPUT", out string logProvider);
if (logProvider == "ASPNetTraceAppender" || logProvider == "ConsoleAppender" || logProvider == "EventLogAppender" || logProvider == "RollingFile")
{
LogConfiguration.SetupLog4Net();
}
LogConfiguration.SetupLog4Net();
}

private static void RemoveArg(ref string[] args, ref int i)
Expand Down Expand Up @@ -434,7 +430,7 @@ public static CultureInfo GetCultureForLang(string lang)
}

#if NETCORE
public static IConfiguration ConfigRoot { get; set; }
public static IConfiguration ConfigRoot { get ; set; }
const string Log4NetShortName = "log4net";
static Version Log4NetVersion = new Version(2, 0, 15);

Expand All @@ -444,17 +440,13 @@ public static CultureInfo GetCultureForLang(string lang)
const string ITextSharpFileName = "iTextSharp.dll";
const string ITextSharpAssemblyName = "itextsharp";
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Config.GetValueOf("LOG_OUTPUT", out string logProvider);
if (logProvider == "ASPNetTraceAppender" || logProvider == "ConsoleAppender" || logProvider == "EventLogAppender" || logProvider == "RollingFile")
{
var requestedAssembly = new AssemblyName(args.Name);
if (requestedAssembly.Name == Log4NetShortName){
requestedAssembly.Version = Log4NetVersion;
return Assembly.Load(requestedAssembly);
}
{
var requestedAssembly = new AssemblyName(args.Name);
if (requestedAssembly.Name == Log4NetShortName){
requestedAssembly.Version = Log4NetVersion;
return Assembly.Load(requestedAssembly);
}

if (args.Name.StartsWith(ConfigurationManagerBak))
{
string fileName = Path.Combine(FileUtil.GetStartupDirectory(), ConfigurationManagerFileName);
Expand Down Expand Up @@ -621,7 +613,6 @@ static NameValueCollection config

}
configLoaded = true;
GxContext.configurationLoaded = configLoaded;
log = GXLoggerFactory.GetLogger<Config>();

string logConfigFile = GxContext.IsHttpContext ? "log.config" : "log.console.config";
Expand Down
1 change: 0 additions & 1 deletion dotnet/src/dotnetframework/GxClasses/Data/GXDataCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,6 @@ public void AddPreparedStmt(string stmt, int cursorId)
if (!preparedStmtCache.TryGetValue(stmt, out s))
{
GXLogging.Info(log, "AddPreparedStmt, totalCachedStmtCursors:" + totalCachedCursors + ", cursorId: " + cursorId + ", stmt:" + stmt);
//GXLogging.Info(log, "AddPreparedStmt, totalCachedStmtCursors: {totalCachedCursors} cursorId: {cursorId} stmt {stmt}",totalCachedCursors.ToString(),cursorId.ToString(),stmt);
totalCachedCursors++;
CheckCacheSize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class MiddlewareTest

protected TestServer server;
public MiddlewareTest()
{
GXRouting.ContentRootPath = Directory.GetCurrentDirectory();
{
server = new TestServer(WebHost.CreateDefaultBuilder().UseStartup<Startup>().UseEnvironment(DOTNET_ENVIRONMENT));
GXRouting.ContentRootPath = Directory.GetCurrentDirectory();
server.PreserveExecutionContext= true;
server.CreateClient();
}
Expand Down

0 comments on commit 0aa9f6d

Please sign in to comment.