Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Logary, Loupe and Sentry new logging packages #20

Merged
merged 12 commits into from
Dec 10, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.5</Version>
<Version>0.0.0.6</Version>
<Description>logger wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>log,logger,logging,log4net</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.5</Version>
<Version>0.0.0.6</Version>
<Description>logger wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>log,logger,logging</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static IServiceCollection AddLoggerScoped(this IServiceCollection service
options.ThrowIfNull(nameof(options));
options(new LoggerOption());
services.AddScoped<ILoggerProvider>(service => LoggerOptionBuilder.GetLogger());
services.AddScoped<ILoggerProviderAsync>(service => LoggerOptionBuilder.GetLogger());
services.AddScoped<ILoggerAsyncProvider>(service => LoggerOptionBuilder.GetLogger());
return services;
}

Expand All @@ -46,7 +46,7 @@ public static IServiceCollection AddLoggerTransient(this IServiceCollection serv
options.ThrowIfNull(nameof(options));
options(new LoggerOption());
services.AddTransient<ILoggerProvider>(service => LoggerOptionBuilder.GetLogger());
services.AddTransient<ILoggerProviderAsync>(service => LoggerOptionBuilder.GetLogger());
services.AddTransient<ILoggerAsyncProvider>(service => LoggerOptionBuilder.GetLogger());
return services;
}

Expand All @@ -61,7 +61,7 @@ public static IServiceCollection AddLoggerSingleton(this IServiceCollection serv
options.ThrowIfNull(nameof(options));
options(new LoggerOption());
services.AddSingleton<ILoggerProvider>(service => LoggerOptionBuilder.GetLogger());
services.AddSingleton<ILoggerProviderAsync>(service => LoggerOptionBuilder.GetLogger());
services.AddSingleton<ILoggerAsyncProvider>(service => LoggerOptionBuilder.GetLogger());
return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<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;netcoreapp3.1;net6.0;net48;net7.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>

<PropertyGroup>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.6</Version>
<Description>logger wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>log,logger,logging,logary</PackageTags>
<PackageProjectUrl>https://github.com/EasyMicroservices/Logger</PackageProjectUrl>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.Logger.Logary.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Logary" Version="5.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.Logger\EasyMicroservices.Logger.csproj" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions src/CSharp/EasyMicroservices.Logger.Logary/LogaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using EasyMicroservices.Logger.Logary.Providers;
using EasyMicroservices.Logger.Options;
using Logary;
using System;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
///
/// </summary>
public static class LogaryExtensions
{
/// <summary>
///
/// </summary>
/// <param name="options"></param>
/// <param name="logger"></param>
/// <returns></returns>
public static LoggerOption UseLogary(this LoggerOption options, Logger logger)
{
options.ThrowIfNull(nameof(options));
logger.ThrowIfNull(nameof(logger));
LoggerOptionBuilder.UseLogger(() => new LogaryProvider(logger));
return options;
}
}
}
108 changes: 108 additions & 0 deletions src/CSharp/EasyMicroservices.Logger.Logary/Providers/LogaryProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using EasyMicroservices.Logger.Providers;
using EasyMicroservices.ServiceContracts;
using Logary;
using System;
using System.Linq;

namespace EasyMicroservices.Logger.Logary.Providers;
/// <summary>
///
/// </summary>
public class LogaryProvider : BaseProvider
{
readonly global::Logary.Logger _logger;
/// <summary>
///
/// </summary>
/// <param name="logger"></param>
public LogaryProvider(global::Logary.Logger logger)
{
_logger = logger;
}

/// <summary>
///
/// </summary>
public LogaryProvider()
{
_logger = global::Logary.Log.Create("Default");
}

MessageContract Log(object[] args, LogLevel logLevel)
{
var extracted = Extract(args);
AddNotExistItems(extracted);
var message = MessageModule.Event(logLevel, $"{extracted.Messages.First()}");
_logger.logWithAck(true, logLevel, Microsoft.FSharp.Core.FuncConvert.FromFunc<LogLevel, Message>((x) => message));
if (extracted.HasExceptions)
{
var errormessage = MessageModule.Event(logLevel, $"{extracted.Exceptions.First()}");
_logger.logWithAck(true, logLevel, Microsoft.FSharp.Core.FuncConvert.FromFunc<LogLevel, Message>((x) => errormessage));
}

return (MessageContract)true;
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public override MessageContract Verbose(params object[] args)
{
return Log(args, LogLevel.Verbose);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override MessageContract Debug(params object[] args)
{
return Log(args, LogLevel.Debug);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override MessageContract Information(params object[] args)
{
return Log(args, LogLevel.Info);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override MessageContract Warning(params object[] args)
{
return Log(args, LogLevel.Warn);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public override MessageContract Error(params object[] args)
{
return Log(args, LogLevel.Error);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public override MessageContract Fatal(params object[] args)
{
return Log(args, LogLevel.Fatal);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<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;netcoreapp3.1;net6.0;net48;net7.0</TargetFrameworks>
</PropertyGroup>
</Otherwise>
</Choose>

<PropertyGroup>
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.6</Version>
<Description>logger wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>log,logger,logging,loupe</PackageTags>
<PackageProjectUrl>https://github.com/EasyMicroservices/Logger</PackageProjectUrl>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>.\bin\$(Configuration)\$(TargetFramework)\EasyMicroservices.Logger.Loupe.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Loupe.Agent.Core" Version="5.0.0.14" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasyMicroservices.Logger\EasyMicroservices.Logger.csproj" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions src/CSharp/EasyMicroservices.Logger.Loupe/LoupeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using EasyMicroservices.Logger.Loupe.Providers;
using EasyMicroservices.Logger.Options;
using System;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
///
/// </summary>
public static class LoupeExtensions
{
/// <summary>
///
/// </summary>
/// <param name="options"></param>
/// <returns></returns>
public static LoggerOption UseLoupe(this LoggerOption options)
{
options.ThrowIfNull(nameof(options));
LoggerOptionBuilder.UseLogger(() => new LoupeProvider());
return options;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using EasyMicroservices.Logger.Providers;
using EasyMicroservices.ServiceContracts;
using Gibraltar.Agent;
using System;
using System.Linq;

namespace EasyMicroservices.Logger.Loupe.Providers;
/// <summary>
///
/// </summary>
public class LoupeProvider : BaseProvider
{
/// <summary>
///
/// </summary>
public LoupeProvider()
{

}

MessageContract InternalLog(object[] args, Action<string, object[]> action)
{
var extracted = Extract(args);
AddNotExistItems(extracted);
action($"{extracted.Messages.First()}", null);
if (extracted.HasExceptions)
action($"{extracted.Exceptions.First()}", null);
return (MessageContract)true;
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public override MessageContract Verbose(params object[] args)
{
return InternalLog(args, Log.TraceVerbose);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override MessageContract Debug(params object[] args)
{
return InternalLog(args, Log.TraceVerbose);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override MessageContract Information(params object[] args)
{
return InternalLog(args, Log.TraceInformation);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public override MessageContract Warning(params object[] args)
{
return InternalLog(args, Log.TraceWarning);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public override MessageContract Error(params object[] args)
{
return InternalLog(args, Log.TraceError);
}

/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public override MessageContract Fatal(params object[] args)
{
return InternalLog(args, Log.TraceCritical);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<IsPackable>true</IsPackable>
<Version>0.0.0.5</Version>
<Version>0.0.0.6</Version>
<Description>logger wrapper</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>log,logger,logging,nlog</PackageTags>
Expand Down
Loading