Skip to content

Commit

Permalink
Fix issue to differ get absolute path between Windows and Linux OS fo…
Browse files Browse the repository at this point in the history
…r reading appsettings files if running as ASP.NET Core app and removed unnecessary Console.WriteLine() output.
  • Loading branch information
moberacker committed Jul 13, 2018
1 parent 41e3ac5 commit 2b7335b
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 40 deletions.
6 changes: 3 additions & 3 deletions Log4ALA/ConfigSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class ConfigSettings


#if NETSTANDARD2_0 || NETCOREAPP2_0
private static IConfigurationRoot CloudConfigurationManager = (new ConfigurationBuilder().SetBasePath(CurrentDir)
private static IConfigurationRoot CloudConfigurationManager = (new ConfigurationBuilder().SetBasePath(ContentRootPath)
.AddJsonFile("appsettings.shared_lnk.json", optional: true, reloadOnChange: true)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.env_{AspNetCoreEnvironment}.json", optional: true, reloadOnChange: true)
Expand Down Expand Up @@ -134,11 +134,11 @@ public static string AppsettingsSuffix
}
}

public static string CurrentDir
public static string ContentRootPath
{
get
{
return Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
return IsWindows() ? Directory.GetCurrentDirectory() : Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
}
}

Expand Down
30 changes: 13 additions & 17 deletions Log4ALA/Log4ALAAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,18 @@ public override void ActivateOptions()
log.Inf($"[{this.Name}] - errLoggerName:[{ErrLoggerName}]", true);
}

#if NETSTANDARD2_0 || NETCOREAPP2_0
log.Inf($"[{this.Name}] - appsettings directory:[{ConfigSettings.ContentRootPath}]", true);
log.Inf($"[{this.Name}] - ASPNETCORE_ENVIRONMENT:[{ConfigSettings.AspNetCoreEnvironment}]", true);
log.Inf($"[{this.Name}] - APPSETTINGS_SUFFIX:[{ConfigSettings.AppsettingsSuffix}]", true);

if(ConfigSettings.IsLinux() || ConfigSettings.IsMacOS())
{
System.Console.WriteLine($@"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}|Log4ALA|TRACE|[{this.Name}] - appsettings directory:[{ConfigSettings.ContentRootPath}]");
System.Console.WriteLine($@"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}|Log4ALA|TRACE|[{this.Name}] - ASPNETCORE_ENVIRONMENT:[{ConfigSettings.AspNetCoreEnvironment}]");
System.Console.WriteLine($@"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}|Log4ALA|TRACE|[{this.Name}] - APPSETTINGS_SUFFIX:[{ConfigSettings.AppsettingsSuffix}]");
}
#endif
if (string.IsNullOrWhiteSpace(configSettings.ALAWorkspaceId) && string.IsNullOrWhiteSpace(WorkspaceId))
{
throw new Exception($"the Log4ALAAppender property workspaceId [{WorkspaceId}] shouldn't be empty");
Expand Down Expand Up @@ -278,19 +289,6 @@ public override void ActivateOptions()

log.Inf($"[{this.Name}] - abortTimeoutSeconds:[{ConfigSettings.AbortTimeoutSeconds}]", true);

#if NETSTANDARD2_0 || NETCOREAPP2_0
log.Inf($"[{this.Name}] - appsettings directory:[{ConfigSettings.CurrentDir}]", true);
log.Inf($"[{this.Name}] - ASPNETCORE_ENVIRONMENT:[{ConfigSettings.AspNetCoreEnvironment}]", true);
log.Inf($"[{this.Name}] - APPSETTINGS_SUFFIX:[{ConfigSettings.AppsettingsSuffix}]", true);

if(ConfigSettings.IsLinux() || ConfigSettings.IsMacOS())
{
System.Console.WriteLine($@"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}|Log4ALA|TRACE|[{this.Name}] - appsettings directory:[{ConfigSettings.CurrentDir}]");
System.Console.WriteLine($@"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}|Log4ALA|TRACE|[{this.Name}] - ASPNETCORE_ENVIRONMENT:[{ConfigSettings.AspNetCoreEnvironment}]");
System.Console.WriteLine($@"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff")}|Log4ALA|TRACE|[{this.Name}] - APPSETTINGS_SUFFIX:[{ConfigSettings.AppsettingsSuffix}]");
}
#endif

queueLogger = new QueueLogger(this);

}
Expand Down Expand Up @@ -411,9 +409,7 @@ protected override void OnClose()
{
if (queueLogger != null)
{
//System.Console.WriteLine("LogManager.Shutdown() - now the log4net system will be shutting down...");
queueLogger.AbortWorker();
//System.Console.WriteLine("LogManager.Shutdown() - log4net system shutdown succeeded.");
}
}

Expand Down Expand Up @@ -458,9 +454,9 @@ public static void Inf(this ILog log, string logMessage, bool logMessage2File =
}
}

public static void War(this ILog log, string logMessage)
public static void War(this ILog log, string logMessage, bool logMessage2File = false)
{
if (log != null)
if (logMessage2File && log != null)
{
log.Warn(logMessage);
}
Expand Down
4 changes: 2 additions & 2 deletions Log4ALA/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.1")]
[assembly: AssemblyFileVersion("2.3.1")]
[assembly: AssemblyVersion("2.3.2")]
[assembly: AssemblyFileVersion("2.3.2")]
11 changes: 2 additions & 9 deletions Log4ALA/QueueLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ protected virtual void Run()

int qReadTimeout = (int)appender.QueueReadTimeout;

var batchSizeInBytesOrig = appender.BatchSizeInBytes;
var batchWaitMaxInSecOrig = appender.BatchWaitMaxInSec;
var batchNumItemsOrig = appender.BatchNumItems;
var batchWaitInSecOrig = appender.BatchWaitInSec;

// Send data in queue.
while (true)
{
Expand Down Expand Up @@ -185,7 +180,6 @@ protected virtual void Run()
catch (ThreadInterruptedException ex)
{
string errMessage = $"[{appender.Name}] - Azure Log Analytics HTTP Data Collector API client was interrupted. {ex}";
System.Console.WriteLine(errMessage);
appender.log.Err(errMessage);
appender.extraLog.Err(errMessage);
}
Expand Down Expand Up @@ -295,7 +289,7 @@ public virtual void AddLine(string line)
{
if (!Queue.TryAdd(line))
{
appender.log.War($"[{appender.Name}] - QueueOverflowMessage");
appender.log.War($"[{appender.Name}] - QueueOverflowMessage", appender.LogMessageToFile);
}
}
}
Expand Down Expand Up @@ -384,8 +378,7 @@ private void HttpRequest(string log)
{
// Reopen the lost connection.
string errMessage = $"[{appender.Name}] - reopen lost connection. [{ex.Message}]";
appender.log.War(errMessage);
System.Console.WriteLine(errMessage);
appender.log.War(errMessage, appender.LogMessageToFile);

Connect();
continue;
Expand Down
2 changes: 1 addition & 1 deletion Log4ALA/internalLog4net.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO" />
<levelMax value="INFO" />
<levelMax value="WARN" />
</filter>
</appender>

Expand Down
4 changes: 2 additions & 2 deletions Log4ALATest/Log4ALATest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Log4ALA, Version=2.3.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Log4ALA.2.3.1\lib\net45\Log4ALA.dll</HintPath>
<Reference Include="Log4ALA, Version=2.3.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Log4ALA.2.3.2\lib\net45\Log4ALA.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.5\lib\net45-full\log4net.dll</HintPath>
Expand Down
2 changes: 1 addition & 1 deletion Log4ALATest/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Log4ALA" version="2.3.1" targetFramework="net452" />
<package id="Log4ALA" version="2.3.2" targetFramework="net452" />
<package id="log4net" version="2.0.5" targetFramework="net452" />
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="3.1.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
Expand Down
2 changes: 1 addition & 1 deletion NuGet/Log4ALA.Core/Log4ALA.core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata minClientVersion="3.3.0">
<id>Log4ALA.Core</id>
<title>Log4ALA</title>
<version>2.3.1</version>
<version>2.3.2</version>
<authors>mob</authors>
<owners>mob</owners>
<projectUrl>https://ptv-logistics.github.io/Log4ALA/</projectUrl>
Expand Down
4 changes: 2 additions & 2 deletions NuGet/Log4ALA/Log4ALA.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata minClientVersion="3.3.0">
<id>Log4ALA</id>
<title>Log4ALA</title>
<version>2.3.1</version>
<version>2.3.2</version>
<authors>mob</authors>
<owners>mob</owners>
<projectUrl>https://ptv-logistics.github.io/Log4ALA/</projectUrl>
Expand All @@ -12,7 +12,7 @@
<description>Log4Net appender for Azure Log Analytics (ALA)... sending data to Azure Log Analytics with the HTTP Data Collector API. The data will also be logged/sent asynchronously for high performance and to avoid blocking the caller thread.</description>
<copyright>Copyright © 2018 PTV Group</copyright>
<releaseNotes>
Fix issue to get absolute path on linux for reading appsettings files.
Fix issue to differ get absolute path between Windows and Linux OS for reading appsettings files if running as ASP.NET Core app and removed unnecessary Console.WriteLine() output.
</releaseNotes>
<dependencies>
<group targetFramework="net45">
Expand Down
2 changes: 1 addition & 1 deletion NuGet/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ REM %MSBUILD% build.proj /target:NuGetRestore
REM %MSBUILD% /p:Configuration=Release ..\Log4ALA.sln
REM %MSBUILD% build.proj /target:NuGetPack /property:Configuration=Release;RELEASE=true
REM PackageVersion=4.5.0;PatchVersion=0;PatchCoreVersion=0
%MSBUILD% build.proj /target:BuildAll /property:Configuration=Release;RELEASE=true;MajorVersion=2;MinorVersion=3;PatchVersion=1
%MSBUILD% build.proj /target:BuildAll /property:Configuration=Release;RELEASE=true;MajorVersion=2;MinorVersion=3;PatchVersion=2
pause
2 changes: 1 addition & 1 deletion NuGet/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<MajorVersion Condition="$(MajorVersion) == ''">2</MajorVersion>
<MinorVersion Condition="$(MinorVersion) == ''">3</MinorVersion>
<PatchVersion Condition="$(PatchVersion) == ''">1</PatchVersion>
<PatchVersion Condition="$(PatchVersion) == ''">2</PatchVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 2b7335b

Please sign in to comment.