Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

let LibLog be used by netstandard11 libs (the future of portable) #125

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/LibLog/LibLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,7 +1143,7 @@ private object TranslateLevel(LogLevel logLevel)
#endif
internal class Log4NetLogProvider : LogProviderBase
{
private readonly Func<string, object> _getLoggerByNameDelegate;
private readonly Func<Assembly, string, object> _getLoggerByNameDelegate;
private static bool s_providerIsAvailableOverride = true;

[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "LogManager")]
Expand All @@ -1164,10 +1164,16 @@ public static bool ProviderIsAvailableOverride

public override Logger GetLogger(string name)
{
return new Log4NetLogger(_getLoggerByNameDelegate(name)).Log;
}
#if LIBLOG_PORTABLE
return new Log4NetLogger(_getLoggerByNameDelegate(
typeof(ILog).GetType().GetTypeInfo().Assembly, name)).Log;
#else
return new Log4NetLogger(_getLoggerByNameDelegate(
typeof(ILog).GetType().Assembly, name)).Log;
#endif
}

internal static bool IsLoggerAvailable()
internal static bool IsLoggerAvailable()
{
return ProviderIsAvailableOverride && GetLogManagerType() != null;
}
Expand Down Expand Up @@ -1240,13 +1246,14 @@ private static Type GetLogManagerType()
return Type.GetType("log4net.LogManager, log4net");
}

private static Func<string, object> GetGetLoggerMethodCall()
private static Func<Assembly, string, object> GetGetLoggerMethodCall()
{
Type logManagerType = GetLogManagerType();
MethodInfo method = logManagerType.GetMethodPortable("GetLogger", typeof(string));
ParameterExpression nameParam = Expression.Parameter(typeof(string), "name");
MethodCallExpression methodCall = Expression.Call(null, method, nameParam);
return Expression.Lambda<Func<string, object>>(methodCall, nameParam).Compile();
MethodInfo method = logManagerType.GetMethodPortable("GetLogger", typeof(Assembly), typeof(string));
ParameterExpression assemblyParam = Expression.Parameter(typeof(Assembly), "repositoryAssembly");
ParameterExpression nameParam = Expression.Parameter(typeof(string), "name");
MethodCallExpression methodCall = Expression.Call(null, method, assemblyParam, nameParam);
return Expression.Lambda<Func<Assembly, string, object>>(methodCall, assemblyParam, nameParam).Compile();
}

#if !LIBLOG_PORTABLE
Expand Down
15 changes: 13 additions & 2 deletions src/LibLog/LibLog.nuspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<metadata minClientVersion="3.3.0">
<id>LibLog</id>
<version>4.2.6</version>
<authors>Damian Hickey</authors>
Expand All @@ -27,8 +27,19 @@ This package is a variation of option 3 but will automatically wire things up to
<frameworkAssemblies>
<frameworkAssembly assemblyName="Microsoft.CSharp" />
</frameworkAssemblies>
<dependencies>
<group targetFramework=".NetStandard1.1">
<dependency id="Microsoft.CSharp" version="[4.0.1, )" />
<dependency id="System.Dynamic.Runtime" version="[4.0.11, )" />
</group>
</dependencies>
<contentFiles>
<files include="contentFiles\cs\**\*.*" buildAction="Compile" />
</contentFiles>
</metadata>
<files>
<file src="LibLog.cs.pp" target="content\App_Packages\LibLog.4.2\LibLog.cs.pp" />
<file src="LibLog.cs.pp" target="content\App_Packages\LibLog.4.2\LibLog.cs.pp" />
<file src="LibLog.cs.pp" target="contentFiles\cs\any" />
<file src="LibLog.cs.pp" target="contentFiles\cs\netstandard1.1" />
</files>
</package>