Initial add
This commit is contained in:
Родитель
0f9f8d598f
Коммит
e1ea75dd27
|
@ -0,0 +1,25 @@
|
|||
image: Visual Studio 2017
|
||||
configuration: Release
|
||||
platform: Any CPU
|
||||
|
||||
install:
|
||||
- ps: $env:build_version = (Select-Xml -Path ".\package.props" -XPath "/Project/PropertyGroup/Version" | Select-Object -ExpandProperty Node).InnerText
|
||||
- ps: Update-AppveyorBuild -Version "$env:build_version.$env:APPVEYOR_BUILD_NUMBER"
|
||||
|
||||
dotnet_csproj:
|
||||
patch: false
|
||||
|
||||
before_build:
|
||||
- cmd: dotnet restore
|
||||
|
||||
build:
|
||||
project: package.sln
|
||||
parallel: true
|
||||
verbosity: minimal
|
||||
|
||||
test_script:
|
||||
- cmd: dotnet test --framework net47 --verbosity q
|
||||
|
||||
artifacts:
|
||||
- path: '**\Unity.*.nupkg'
|
||||
name: 'Unity'
|
|
@ -0,0 +1,13 @@
|
|||
<Project>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0</Version>
|
||||
<PackageReleaseNotes>This package is distributed as .NET Standard 2.0</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<UnityContainerVersion>5.*</UnityContainerVersion>
|
||||
<UnityAbstractionsVersion>3.*</UnityAbstractionsVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27004.2005
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Unity.Microsoft.Logging", "src\Unity.Microsoft.Logging.csproj", "{74B8AD0A-E2DD-42CB-8391-A86586F77529}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Logging.Tests", "tests\Microsoft.Logging.Tests.csproj", "{9C31FECA-443B-4953-886A-F7DE3597A040}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{74B8AD0A-E2DD-42CB-8391-A86586F77529}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{74B8AD0A-E2DD-42CB-8391-A86586F77529}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{74B8AD0A-E2DD-42CB-8391-A86586F77529}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{74B8AD0A-E2DD-42CB-8391-A86586F77529}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9C31FECA-443B-4953-886A-F7DE3597A040}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9C31FECA-443B-4953-886A-F7DE3597A040}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C31FECA-443B-4953-886A-F7DE3597A040}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C31FECA-443B-4953-886A-F7DE3597A040}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F9EAE93A-CE20-498A-8BC7-183974E8323A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,99 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Unity.Attributes;
|
||||
using Unity.Builder;
|
||||
using Unity.Extension;
|
||||
using Unity.Policy;
|
||||
|
||||
namespace Unity.Microsoft.Logging
|
||||
{
|
||||
public class LoggingExtension : UnityContainerExtension, IBuildPlanCreatorPolicy
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private readonly MethodInfo _createLoggerMethod;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructors
|
||||
|
||||
[InjectionConstructor]
|
||||
public LoggingExtension()
|
||||
: this(new LoggerFactory())
|
||||
{
|
||||
}
|
||||
|
||||
public LoggingExtension(ILoggerFactory loggerFactory)
|
||||
{
|
||||
LoggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
|
||||
_createLoggerMethod = LoggerFactory.GetType().GetTypeInfo().GetDeclaredMethods(nameof(ILoggerFactory.CreateLogger))
|
||||
.First(m => m.IsGenericMethod);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Public Members
|
||||
|
||||
public ILoggerFactory LoggerFactory { get; } = new LoggerFactory();
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Implementation
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
Context.Policies.Set<IBuildPlanCreatorPolicy>(this, typeof(ILogger<>));
|
||||
}
|
||||
|
||||
IBuildPlanPolicy IBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, INamedType buildKey)
|
||||
{
|
||||
var itemType = (context ?? throw new ArgumentNullException(nameof(context))).BuildKey
|
||||
.Type
|
||||
.GetTypeInfo()
|
||||
.GenericTypeArguments
|
||||
.First();
|
||||
var buildMethod = _createLoggerMethod.MakeGenericMethod(itemType)
|
||||
.CreateDelegate(typeof(DynamicBuildPlanMethod));
|
||||
|
||||
return new DynamicMethodBuildPlan((DynamicBuildPlanMethod)buildMethod);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Nested Types
|
||||
|
||||
public delegate void DynamicBuildPlanMethod(IBuilderContext context);
|
||||
|
||||
private class DynamicMethodBuildPlan : IBuildPlanPolicy
|
||||
{
|
||||
private readonly DynamicBuildPlanMethod _buildMethod;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="buildMethod"></param>
|
||||
public DynamicMethodBuildPlan(DynamicBuildPlanMethod buildMethod)
|
||||
{
|
||||
_buildMethod = buildMethod;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public void BuildUp(IBuilderContext context)
|
||||
{
|
||||
_buildMethod(context);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\package.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<FileVersion>$(Version).0</FileVersion>
|
||||
<AssemblyVersion>$(Version).0</AssemblyVersion>
|
||||
<PackageId>Unity.Microsoft.Logging</PackageId>
|
||||
<Description>Unity adapter for Microsoft.Extensions.Logging</Description>
|
||||
<Copyright>Copyright © Microsoft.Practices.Unity 2018</Copyright>
|
||||
<PackageProjectUrl>https://github.com/unitycontainer/microsoft-logging </PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/unitycontainer/microsoft-logging </RepositoryUrl>
|
||||
<PackageLicenseUrl>https://github.com/unitycontainer/microsoft-logging /blob/master/LICENSE</PackageLicenseUrl>
|
||||
<PackageIconUrl>https://avatars1.githubusercontent.com/u/12849707</PackageIconUrl>
|
||||
<PackageTags>Unity Container unitycontainer Microsoft.Practices.Unity IoC Microsoft.Extensions.Logging</PackageTags>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<Authors>Microsoft.Practices.Unity</Authors>
|
||||
<Company>Microsoft.Practices.Unity</Company>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>package.snk</AssemblyOriginatorKeyFile>
|
||||
<DelaySign>false</DelaySign>
|
||||
<RootNamespace>Unity.Microsoft.Logging</RootNamespace>
|
||||
<UnityAbstractions>..\..\Abstractions\src\Unity.Abstractions.csproj</UnityAbstractions>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<TargetFrameworks>netstandard2.0;net47;net45</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<DebugType>Full</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="Exists('$(UnityAbstractions)')">
|
||||
<ProjectReference Include="$(UnityAbstractions)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="!Exists('$(UnityAbstractions)')">
|
||||
<PackageReference Include="Unity.Abstractions" Version="$(UnityAbstractionsVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Двоичный файл не отображается.
|
@ -0,0 +1,66 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Unity;
|
||||
using Unity.Microsoft.Logging;
|
||||
|
||||
namespace Microsoft.Logging.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class LoggingFixture
|
||||
{
|
||||
private static IUnityContainer _container;
|
||||
private LoggedType _instance;
|
||||
|
||||
[ClassInitialize]
|
||||
public static void Setup(TestContext context)
|
||||
{
|
||||
}
|
||||
|
||||
[TestInitialize]
|
||||
public void TestSetup()
|
||||
{
|
||||
_container = new UnityContainer();
|
||||
_container.AddNewExtension<LoggingExtension>();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void microsoft_logging_default_name()
|
||||
{
|
||||
Assert.IsNotNull(_container.Configure<LoggingExtension>().LoggerFactory);
|
||||
|
||||
var ss = _container.Configure<LoggingExtension>().LoggerFactory.CreateLogger<LoggedType>();
|
||||
Assert.IsInstanceOfType(_container.Configure<LoggingExtension>().LoggerFactory,
|
||||
typeof(ILoggerFactory));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void microsoft_logging_can_resolve_test_type()
|
||||
{
|
||||
_instance = _container.Resolve<LoggedType>();
|
||||
Assert.IsNotNull(_instance);
|
||||
Assert.IsNotNull(_instance.ResolvedLogger);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void microsoft_logging_correct_type()
|
||||
{
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void microsoft_logging_change_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class LoggedType
|
||||
{
|
||||
public LoggedType(ILogger<LoggedType> log)
|
||||
{
|
||||
ResolvedLogger = log;
|
||||
}
|
||||
|
||||
public ILogger<LoggedType> ResolvedLogger { get; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Import Project="..\package.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net47</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\src\Unity.Microsoft.Logging.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<PropertyGroup>
|
||||
<UnityAbstractions>..\..\Abstractions\src\Unity.Abstractions.csproj</UnityAbstractions>
|
||||
<UnityContainer>..\..\Container\src\Unity.Container.csproj</UnityContainer>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="Exists('$(UnityAbstractions)')">
|
||||
<ProjectReference Include="$(UnityAbstractions)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="Exists('$(UnityContainer)')">
|
||||
<ProjectReference Include="$(UnityContainer)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="!Exists('$(UnityAbstractions)')">
|
||||
<PackageReference Include="Unity.Abstractions" Version="$(UnityAbstractionsVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="!Exists('$(UnityContainer)')">
|
||||
<PackageReference Include="Unity.Container" Version="$(UnityContainerVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
|
||||
<HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.logging.abstractions\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Загрузка…
Ссылка в новой задаче