-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Ali-YousefiTelori/develop
Add Support for Dependency injection
- Loading branch information
Showing
21 changed files
with
304 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>0.0.0.1</Version> | ||
<Version>0.0.0.2</Version> | ||
<Description>logger wrapper</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>log,logger,logging,log4net</PackageTags> | ||
|
27 changes: 27 additions & 0 deletions
27
src/CSharp/EasyMicroservices.Logger/EasyMicroservices.Logger. Log4net/Log4netExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using EasyMicroservices.Logger.Log4net.Providers; | ||
using EasyMicroservices.Logger.Options; | ||
using log4net; | ||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static class Log4netExtensions | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <param name="log"></param> | ||
/// <returns></returns> | ||
public static LoggerOption UseLog4net(this LoggerOption options, ILog log) | ||
{ | ||
options.ThrowIfNull(nameof(options)); | ||
log.ThrowIfNull(nameof(log)); | ||
LoggerOptionBuilder.UseLogger(() => new Log4netProvider(log)); | ||
return options; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...roservices.Logger.DependencyInjection/EasyMicroservices.Logger.DependencyInjection.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Choose> | ||
<When Condition="$(SolutionFileName.Contains('Net7'))"> | ||
<PropertyGroup> | ||
<TargetFrameworks>net7.0</TargetFrameworks> | ||
</PropertyGroup> | ||
</When> | ||
<Otherwise> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net48;net7.0</TargetFrameworks> | ||
</PropertyGroup> | ||
</Otherwise> | ||
</Choose> | ||
|
||
<PropertyGroup> | ||
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>0.0.0.1</Version> | ||
<Description>logger wrapper</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>log,logger,logging</PackageTags> | ||
<PackageProjectUrl>https://github.com/EasyMicroservices/Logger</PackageProjectUrl> | ||
<LangVersion>latest</LangVersion> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.Logger.DependencyInjection.xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\EasyMicroservices.Logger\EasyMicroservices.Logger.csproj" /> | ||
</ItemGroup> | ||
</Project> |
26 changes: 26 additions & 0 deletions
26
...EasyMicroservices.Logger/EasyMicroservices.Logger.DependencyInjection/LoggerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using EasyMicroservices.Logger.Interfaces; | ||
using EasyMicroservices.Logger.Options; | ||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static class LoggerExtensions | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="services"></param> | ||
/// <param name="options"></param> | ||
/// <returns></returns> | ||
public static IServiceCollection AddLogger(this IServiceCollection services, Action<LoggerOption> options) | ||
{ | ||
options.ThrowIfNull(nameof(options)); | ||
options(new LoggerOption()); | ||
services.AddScoped(service => LoggerOptionBuilder.GetLogger()); | ||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>0.0.0.1</Version> | ||
<Version>0.0.0.2</Version> | ||
<Description>logger wrapper</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>log,logger,logging,nlog</PackageTags> | ||
|
26 changes: 26 additions & 0 deletions
26
src/CSharp/EasyMicroservices.Logger/EasyMicroservices.Logger.NLog/NLogExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using EasyMicroservices.Logger.NLog.Providers; | ||
using EasyMicroservices.Logger.Options; | ||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static class NLogExtensions | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <param name="logger"></param> | ||
/// <returns></returns> | ||
public static LoggerOption UseLog4net(this LoggerOption options, NLog.Logger logger) | ||
{ | ||
options.ThrowIfNull(nameof(options)); | ||
logger.ThrowIfNull(nameof(logger)); | ||
LoggerOptionBuilder.UseLogger(() => new NLogProvider(logger)); | ||
return options; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
<Platforms>AnyCPU;x64;x86</Platforms> | ||
<Authors>EasyMicroservices</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>0.0.0.1</Version> | ||
<Version>0.0.0.2</Version> | ||
<Description>logger wrapper</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>log,logger,logging,serilog</PackageTags> | ||
|
27 changes: 27 additions & 0 deletions
27
src/CSharp/EasyMicroservices.Logger/EasyMicroservices.Logger.Serilog/SerilogExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using EasyMicroservices.Logger.Options; | ||
using EasyMicroservices.Logger.Serilog.Providers; | ||
using Serilog; | ||
using System; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public static class SerilogExtensions | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
/// <param name="options"></param> | ||
/// <param name="loggerConfiguration"></param> | ||
/// <returns></returns> | ||
public static LoggerOption UseLog4net(this LoggerOption options, LoggerConfiguration loggerConfiguration) | ||
{ | ||
options.ThrowIfNull(nameof(options)); | ||
loggerConfiguration.ThrowIfNull(nameof(loggerConfiguration)); | ||
LoggerOptionBuilder.UseLogger(() => new SerilogProvider(loggerConfiguration)); | ||
return options; | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/CSharp/EasyMicroservices.Logger/EasyMicroservices.Logger.Tests/BaseProviderAsyncTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using EasyMicroservices.Logger.Interfaces; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace EasyMicroservices.Logger.Tests | ||
{ | ||
public abstract class BaseProviderAsyncTest | ||
{ | ||
ILoggerProviderAsync _logger; | ||
public BaseProviderAsyncTest(ILoggerProviderAsync logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello world Debug")] | ||
[InlineData("Hello world Debug 2")] | ||
public async Task MessageDebug(string message) | ||
{ | ||
await _logger.DebugAsync(message); | ||
await _logger.DebugAsync(message, new Exception($"exception {message}")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello world Verbose")] | ||
[InlineData("Hello world Verbose 2")] | ||
public async Task MessageVerbose(string message) | ||
{ | ||
await _logger.VerboseAsync(message); | ||
await _logger.VerboseAsync(message, new Exception($"exception {message}")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello world Information")] | ||
[InlineData("Hello world Information 2")] | ||
public async Task MessageInformation(string message) | ||
{ | ||
await _logger.InformationAsync(message); | ||
await _logger.InformationAsync(message, new Exception($"exception {message}")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello world Warning")] | ||
[InlineData("Hello world Warning 2")] | ||
public async Task MessageWarning(string message) | ||
{ | ||
await _logger.WarningAsync(message); | ||
await _logger.WarningAsync(message, new Exception($"exception {message}")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello world Error")] | ||
[InlineData("Hello world Error 2")] | ||
public async Task MessageError(string message) | ||
{ | ||
await _logger.ErrorAsync(message); | ||
await _logger.ErrorAsync(message, new Exception($"exception {message}")); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello world Fatal")] | ||
[InlineData("Hello world Fatal 2")] | ||
public async Task MessageFatal(string message) | ||
{ | ||
await _logger.FatalAsync(message); | ||
await _logger.FatalAsync(message, new Exception($"exception {message}")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks> | ||
<Authors>EasyMicroservices</Authors> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Version>0.0.0.1</Version> | ||
<Version>0.0.0.2</Version> | ||
<Description>Logger and Auditing system</Description> | ||
<Copyright>[email protected]</Copyright> | ||
<PackageTags>logging,auditing</PackageTags> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/CSharp/EasyMicroservices.Logger/EasyMicroservices.Logger/Options/LoggerOption.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace EasyMicroservices.Logger.Options | ||
{ | ||
/// <summary> | ||
/// | ||
/// </summary> | ||
public class LoggerOption | ||
{ | ||
} | ||
} |
Oops, something went wrong.