diff --git a/dotnet/DotNetStandardClasses.sln b/dotnet/DotNetStandardClasses.sln index 16834f162..bad8eab6d 100644 --- a/dotnet/DotNetStandardClasses.sln +++ b/dotnet/DotNetStandardClasses.sln @@ -257,6 +257,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GXOtel.Diagnostics", "src\d EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetCoreCmdTest", "test\DotNetCoreCmdTest\DotNetCoreCmdTest.csproj", "{956402BD-AC8C-426E-961B-B77B3F3EDAEB}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{46DAAFD1-FAF5-4904-8EC5-406BE04E5538}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogTest", "test\benchmarks\LogTest\LogTest.csproj", "{A1DBDCE0-4F09-445F-A202-9B260CDD46CF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -627,7 +631,10 @@ Global {956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Debug|Any CPU.Build.0 = Debug|Any CPU {956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Release|Any CPU.ActiveCfg = Release|Any CPU {956402BD-AC8C-426E-961B-B77B3F3EDAEB}.Release|Any CPU.Build.0 = Release|Any CPU - + {A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1DBDCE0-4F09-445F-A202-9B260CDD46CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -751,7 +758,8 @@ Global {0FCFB078-5584-469F-92CC-61B0A6216D0D} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC} {A42066E8-DDB9-4767-AEFA-E6D13EFF051A} = {BBE020D4-C0FF-41A9-9EB1-D1EE12CC4BB8} {956402BD-AC8C-426E-961B-B77B3F3EDAEB} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC} - + {46DAAFD1-FAF5-4904-8EC5-406BE04E5538} = {1D6F1776-FF4B-46C2-9B3D-BC46CCF049DC} + {A1DBDCE0-4F09-445F-A202-9B260CDD46CF} = {46DAAFD1-FAF5-4904-8EC5-406BE04E5538} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C} diff --git a/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs b/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs index d1947ed42..b413bdd2d 100644 --- a/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs +++ b/dotnet/src/dotnetframework/GxClasses/Diagnostics/Log.cs @@ -21,29 +21,21 @@ private enum LogLevel Error = 20, Fatal = 30 } -#if NETCORE - static ILoggerFactory _instance = GXLogService.GetLogFactory(); -#endif - + private static readonly string DefaultRepository = LogManager.GetRepository().Name; + private static readonly string DefaultUserLogNamespace = Config.GetValueOf("USER_LOG_NAMESPACE", LogConfiguration.USER_LOG_TOPIC); + private static readonly IGXLogger GlobalLog = new GXLoggerLog4Net(LogManager.GetLogger(DefaultRepository, DefaultUserLogNamespace)); + internal static IGXLogger GetLogger(string topic) { - string defaultUserLogNamespace = Configuration.Config.GetValueOf("USER_LOG_NAMESPACE", LogConfiguration.USER_LOG_TOPIC); - string loggerName = defaultUserLogNamespace; if (!string.IsNullOrEmpty(topic)) { - loggerName = topic.StartsWith("$") ? topic.Substring(1) : string.Format("{0}.{1}", defaultUserLogNamespace, topic.Trim()); + string loggerName = topic.StartsWith("$") ? topic.Substring(1) : string.Format("{0}.{1}", DefaultUserLogNamespace, topic.Trim()); + return GXLoggerFactory.GetLogger(loggerName); } -#if NETCORE - if (_instance != null) + else { - return new GXLoggerMsExtensions(_instance.CreateLogger(loggerName)); + return GlobalLog; } - string defaultRepository = LogManager.GetRepository(System.Reflection.Assembly.GetEntryAssembly()).Name; -#else - string defaultRepository = LogManager.GetRepository().Name; -#endif - return new GXLoggerLog4Net(log4net.LogManager.GetLogger(defaultRepository, loggerName)); - } public static void Write(int logLevel, string message, string topic) diff --git a/dotnet/test/benchmarks/LogTest/LogTest.cs b/dotnet/test/benchmarks/LogTest/LogTest.cs new file mode 100644 index 000000000..6c9273380 --- /dev/null +++ b/dotnet/test/benchmarks/LogTest/LogTest.cs @@ -0,0 +1,48 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Reports; +using BenchmarkDotNet.Running; +using GeneXus.Diagnostics; +using Xunit; +namespace BenchmarkTest +{ + public class LoggerBenchmark + { + [Params(1000)] + public int N; + const int Debug = 5; + + [Benchmark] + public void Write_PerformanceTest() + { + for (int i = 0; i < N; i++) + { + Log.Write("Test Message", "Test Topi", Debug); + } + } + } + + public class PerformanceTests + { + const double MAX_NANOSECONDS = 150000; + [Fact] + public void RunLoggerBenchmark() + { +#if DEBUG + var config = DefaultConfig.Instance.WithOptions(ConfigOptions.DisableOptimizationsValidator); + Summary summary = BenchmarkRunner.Run(config); +#else + Summary summary = BenchmarkRunner.Run(); +#endif + Assert.NotEmpty(summary.Reports); + foreach (BenchmarkReport report in summary.Reports) + { + Assert.NotEmpty(report.AllMeasurements); + foreach (Measurement runMeasure in report.AllMeasurements) + { + Assert.InRange(runMeasure.Nanoseconds, low: 0, high: MAX_NANOSECONDS); + } + } + } + } +} \ No newline at end of file diff --git a/dotnet/test/benchmarks/LogTest/LogTest.csproj b/dotnet/test/benchmarks/LogTest/LogTest.csproj new file mode 100644 index 000000000..afb2749c5 --- /dev/null +++ b/dotnet/test/benchmarks/LogTest/LogTest.csproj @@ -0,0 +1,36 @@ + + + + net462 + false + true + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/dotnet/test/benchmarks/LogTest/appsettings.json b/dotnet/test/benchmarks/LogTest/appsettings.json new file mode 100644 index 000000000..31bce50e5 --- /dev/null +++ b/dotnet/test/benchmarks/LogTest/appsettings.json @@ -0,0 +1,64 @@ +{ + "appSettings": { + "AppMainNamespace": "GeneXus.Programs", + "DataStore1": "Default", + "DataStore-Count": "1", + "DataStore-Default": "Default", + "Connection-Default-DBMS": "sqlserver", + "Connection-Default-Port": "", + "Connection-Default-LockTimeout": "0", + "Connection-Default-LockRetryCount": "10", + "Connection-Default-IsolationLevel": "CR", + "Connection-Default-Datasource": "", + "Connection-Default-User": "", + "Connection-Default-Password": "", + "Connection-Default-DB": "", + "Connection-Default-Schema": "", + "Connection-Default-Opts": "", + "Connection-Default-TrnInt": "1", + "DateFormat": "MDY", + "YearLimit": "1940", + "TimeAmPmFormat": "12", + "VER_STAMP": "20210602.093942", + "CS_BLOB_PATH": "PublicTempStorage", + "TMPMEDIA_DIR": "PrivateTempStorage", + "PRINT_LAYOUT_METADATA_DIR": "LayoutMetadata", + "StorageTimeZone": "1", + "LOGIN_AS_USERID": "0", + "LANGUAGE": "eng", + "LANG_NAME": "English", + "DECIMAL_POINT": ".", + "DATE_FMT": "MDY", + "CTOD_DATE_FMT": "L", + "Culture": "en-US", + "Theme": "Carmine", + "UseNamedParameters": "1", + "EnableIntegratedSecurity": "0", + "MAX_CURSOR": "100", + "STATIC_CONTENT": "", + "GX_BUILD_NUMBER": "11103481", + "CACHE_CONTENT_EXPIRATION": "36", + "ENABLE_MANAGEMENT": "0", + "COMPRESS_HTML": "1", + "IE_COMPATIBILITY_VIEW": "EmulateIE7", + "DocumentType": "HTML5", + "EXPOSE_METADATA": "0", + "SMART_CACHING": "0", + "wcf:serviceHostingEnvironment:useClassicReadEntityBodyMode": "true", + "HTTP_PROTOCOL": "Unsecure", + "SAMESITE_COOKIE": "Lax", + "CACHE_INVALIDATION_TOKEN": "20216211291931", + "CORS_ALLOW_ORIGIN": "https://normal-website.com", + "MY_CUSTOM_PTY": "DEFAULT_VALUE" + }, + "languages": { + "English": { + "code": "eng", + "culture": "en-US", + "date_fmt": "MDY", + "decimal_point": ".", + "thousand_sep": ",", + "time_fmt": "12" + } + } +} \ No newline at end of file diff --git a/dotnet/test/benchmarks/LogTest/log.console.config b/dotnet/test/benchmarks/LogTest/log.console.config new file mode 100644 index 000000000..b52a4d897 --- /dev/null +++ b/dotnet/test/benchmarks/LogTest/log.console.config @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +