Skip to content

Commit

Permalink
Fixed callbackOnCollectedDelegate exception when provider has errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Turrican committed Apr 3, 2019
1 parent c1589cb commit 9c3f327
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 51 deletions.
Expand Up @@ -4,16 +4,16 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Platforms>AnyCPU;x64;x86</Platforms>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.3.8</Version>
<Version>1.3.9</Version>
<Authors>Exilon &amp; Turrican</Authors>
<Company>Exilon</Company>
<Description>Abstractions and user interfaces for QuickLogger</Description>
<PackageIconUrl>https://github.com/exilon/QuickLogger/blob/master/QuickLogger.png</PackageIconUrl>
<RepositoryUrl>https://github.com/exilon/QuickLogger</RepositoryUrl>
<RepositoryType>GIT</RepositoryType>
<PackageTags>Logger, Native, NetStandard, C++, C#, Delphi, CrossPlatform, Injectable</PackageTags>
<AssemblyVersion>1.3.8.0</AssemblyVersion>
<FileVersion>1.3.8.0</FileVersion>
<AssemblyVersion>1.3.9.0</AssemblyVersion>
<FileVersion>1.3.9.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand Down
Expand Up @@ -99,7 +99,6 @@ private bool FindStringInsideFile(string fileName, string line)
[OneTimeSetUp]
public void SetUp()
{

_configPath = Directory.GetParent(Assembly.GetAssembly(typeof(QuickLogger_Integration_Should)).Location).Parent.Parent.FullName;
_fileloggerPath = Path.Combine(_configPath, _fileloggerName);
_configPath = Path.Combine(_configPath, _configName);
Expand All @@ -111,8 +110,6 @@ public void SetUp()
public void TearDown()
{
// Manual Free of native resources
((IDisposable)_logger).Dispose();

if (File.Exists(_configPath)) { File.Delete(_configPath); }
}

Expand Down Expand Up @@ -178,6 +175,7 @@ public void Add_Logger_Default_File_Provider_To_New_Logger()
_logger.Success("Success line");
_logger.DisableProvider(loggerProvider);
_logger.RemoveProvider(loggerProvider);
System.Threading.Thread.Sleep(0);
Assert.That(FindStringInsideFile(_fileloggerPath, "Info line"), Is.True);
Assert.That(FindStringInsideFile(_fileloggerPath, "Custom line"), Is.True);
Assert.That(FindStringInsideFile(_fileloggerPath, "Error line"), Is.True);
Expand Down
22 changes: 0 additions & 22 deletions library/wrappers/dotnet/QuickLogger/QuickLogger.sln
Expand Up @@ -15,23 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickLogger.Sample.NetCore.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "QuickLogger.DefaultSettings.Generator", "QuickLogger.DefaultSettings.Generator\QuickLogger.DefaultSettings.Generator.csproj", "{4657DD2C-79C1-48D4-976E-063FE9DD3E44}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "native", "native", "{EBCF30E0-2486-4DD9-A5FF-957E36B0067D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "x64", "x64", "{BB48CCCF-2451-48CD-BA74-4869C20A45C4}"
ProjectSection(SolutionItems) = preProject
..\..\..\bin\Win64\Release\QuickLogger.dll = ..\..\..\bin\Win64\Release\QuickLogger.dll
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "x86", "x86", "{5E9AF9E1-D368-4A51-9B63-CD3F682EE97D}"
ProjectSection(SolutionItems) = preProject
..\..\..\bin\Win32\Release\QuickLogger.dll = ..\..\..\bin\Win32\Release\QuickLogger.dll
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "x86_64-linux", "x86_64-linux", "{DA6F95D3-64F0-428F-B92B-DEC806C36266}"
ProjectSection(SolutionItems) = preProject
..\..\..\bin\x86_64-linux\libquicklogger.so = ..\..\..\bin\x86_64-linux\libquicklogger.so
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -118,11 +101,6 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BB48CCCF-2451-48CD-BA74-4869C20A45C4} = {EBCF30E0-2486-4DD9-A5FF-957E36B0067D}
{5E9AF9E1-D368-4A51-9B63-CD3F682EE97D} = {EBCF30E0-2486-4DD9-A5FF-957E36B0067D}
{DA6F95D3-64F0-428F-B92B-DEC806C36266} = {EBCF30E0-2486-4DD9-A5FF-957E36B0067D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {939878F6-E47F-4B28-B1FE-3DBA9BD0434F}
EndGlobalSection
Expand Down
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Platforms>AnyCPU;x64;x86</Platforms>
<Version>1.4.3</Version>
<Version>1.4.6</Version>
<Description>native, Testable and Injectable multi-provider logging library for .NET</Description>
<Copyright>Exilon &amp; Turric4m</Copyright>
<Copyright>Exilon &amp; Turric4n</Copyright>
<PackageProjectUrl>https://github.com/exilon/QuickLogger</PackageProjectUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>1.4.3.0</AssemblyVersion>
<FileVersion>1.4.3.0</FileVersion>
<AssemblyVersion>1.4.6.0</AssemblyVersion>
<FileVersion>1.4.6.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -30,7 +30,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="libquickloggernative.redist" Version="1.4.6">
<PackageReference Include="libquickloggernative.redist" Version="1.4.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Expand Down
Expand Up @@ -12,7 +12,7 @@
namespace QuickLogger.NetStandard
{
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
public class QuickLoggerNative : ILogger, IDisposable
public class QuickLoggerNative : ILogger
{
//Native Library function types and marshalling (Native to safe)
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode)]
Expand Down Expand Up @@ -114,29 +114,23 @@ public class QuickLoggerNative : ILogger, IDisposable
private static unsafe IsQueueEmptyNative isQueueEmptyNative;
private static unsafe ResetProviderNative resetProviderNative;
private static unsafe GetCurrentProvidersNative getCurrentProvidersNative;

private static IntPtr nativeHwnd;
private static UnhandledExceptionEventHandler unhandledEventHandler;
private string _rootPath;
private string[] libNames = { "\\x64\\QuickLogger.dll", "\\x86\\QuickLogger.dll", "\\x64\\libquicklogger.so", "\\x86\\libquicklogger.so" };

private static List<System.Delegate> delegates = new List<System.Delegate>();
public QuickLoggerNative(string rootPath, bool handleExceptions = true)
{
if (string.IsNullOrEmpty(rootPath)) { _rootPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); }
else { _rootPath = rootPath; }
for (int x = 0; x < libNames.Count(); x++) { libNames[x] = _rootPath + libNames[x]; }
_quickloggerlib = new NativeLibrary(libNames);
nativeHwnd = _quickloggerlib.Handle;
MapFunctionPointers();
// Current domain (thread) exceptions only doesn't work on a webserver
if (handleExceptions) { setupCurrentDomainExceptionHandler(); }
}

~QuickLoggerNative() { Dispose(); }

public void Dispose()
{
GC.SuppressFinalize(this);
}

private void setupCurrentDomainExceptionHandler()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
Expand Down Expand Up @@ -215,14 +209,32 @@ public void Critical(string message)
}
private void AssignDelegatesToNative(ILoggerProvider provider)
{
addWrapperErrorDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderErrorEventHandler(provider.OnError)));
addWrapperFailDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderFailToLog(provider.OnFailToLog)));
addWrapperCriticalErrorDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderCriticalErrorEventHandler(provider.OnCriticalError)));
addWrapperQueueErrorDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderQueueErrorEventHandler(provider.OnQueueError)));
addWrapperRestartDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderRestartEventHandler(provider.OnRestart)));
addWrapperSendLimitsDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderSendLimits(provider.OnSendLimitsReached)));
addWrapperStartDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderStartEventHandler(provider.OnStarted)));
addWrapperStatusChangedDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(new ProviderStatusChangedEventHandler(provider.OnStatusChanged)));
var providererroreventhandler = new ProviderErrorEventHandler(provider.OnError) ;
var providerfailtolog = new ProviderFailToLog(provider.OnFailToLog);
var providercriticalerroreventhandler = new ProviderCriticalErrorEventHandler(provider.OnCriticalError);
var providerQueueError = new ProviderQueueErrorEventHandler(provider.OnQueueError);
var providerRestartEvent = new ProviderRestartEventHandler(provider.OnRestart);
var providerSendLimits = new ProviderSendLimits(provider.OnSendLimitsReached);
var providerStartEventHandler = new ProviderStartEventHandler(provider.OnStarted);
var providerStatusChanged = new ProviderStatusChangedEventHandler(provider.OnStatusChanged);

delegates.Add(providererroreventhandler);
delegates.Add(providerfailtolog);
delegates.Add(providercriticalerroreventhandler);
delegates.Add(providerQueueError);
delegates.Add(providerRestartEvent);
delegates.Add(providerSendLimits);
delegates.Add(providerStartEventHandler);
delegates.Add(providerStatusChanged);

addWrapperErrorDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providererroreventhandler));
addWrapperFailDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providerfailtolog));
addWrapperCriticalErrorDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providercriticalerroreventhandler));
addWrapperQueueErrorDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providerQueueError));
addWrapperRestartDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providerRestartEvent));
addWrapperSendLimitsDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providerSendLimits));
addWrapperStartDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providerStartEventHandler));
addWrapperStatusChangedDelegateNative?.Invoke(provider.getProviderProperties().GetProviderName(), Marshal.GetFunctionPointerForDelegate(providerStatusChanged));
}
public void AddProvider(ILoggerProvider provider)
{
Expand Down

0 comments on commit 9c3f327

Please sign in to comment.