committed by
GitHub
15 changed files with 66 additions and 64 deletions
@ -1,5 +0,0 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|
||||
<ItemGroup> |
|
||||
<PackageReference Include="Serilog.Sinks.Trace" Version="2.1.0" /> |
|
||||
</ItemGroup> |
|
||||
</Project> |
|
||||
@ -1,5 +1,7 @@ |
|||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup> |
<ItemGroup> |
||||
<PackageReference Include="Serilog" Version="2.4.0" /> |
<PackageReference Include="Serilog" Version="2.5.0" /> |
||||
|
<PackageReference Include="Serilog.Sinks.Trace" Version="2.1.0" /> |
||||
|
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.0" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
</Project> |
</Project> |
||||
|
|||||
@ -0,0 +1,51 @@ |
|||||
|
using System; |
||||
|
using Avalonia.Controls; |
||||
|
using Serilog; |
||||
|
using SerilogLevel = Serilog.Events.LogEventLevel; |
||||
|
|
||||
|
namespace Avalonia.Logging.Serilog |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Extension methods for Serilog logging.
|
||||
|
/// </summary>
|
||||
|
public static class SerilogExtensions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Logs Avalonia events to the <see cref="System.Diagnostics.Debug"/> sink.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="T">The application class type.</typeparam>
|
||||
|
/// <param name="builder">The app builder instance.</param>
|
||||
|
/// <param name="level">The minimum level to log.</param>
|
||||
|
/// <returns>The app builder instance.</returns>
|
||||
|
public static T LogToDebug<T>( |
||||
|
this T builder, |
||||
|
LogEventLevel level = LogEventLevel.Warning) |
||||
|
where T : AppBuilderBase<T>, new() |
||||
|
{ |
||||
|
SerilogLogger.Initialize(new LoggerConfiguration() |
||||
|
.MinimumLevel.Is((SerilogLevel)level) |
||||
|
.WriteTo.Debug(outputTemplate: "{Area}: {Message}") |
||||
|
.CreateLogger()); |
||||
|
return builder; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Logs Avalonia events to the <see cref="System.Diagnostics.Trace"/> sink.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="T">The application class type.</typeparam>
|
||||
|
/// <param name="builder">The app builder instance.</param>
|
||||
|
/// <param name="level">The minimum level to log.</param>
|
||||
|
/// <returns>The app builder instance.</returns>
|
||||
|
public static T LogToTrace<T>( |
||||
|
this T builder, |
||||
|
LogEventLevel level = LogEventLevel.Warning) |
||||
|
where T : AppBuilderBase<T>, new() |
||||
|
{ |
||||
|
SerilogLogger.Initialize(new LoggerConfiguration() |
||||
|
.MinimumLevel.Is((SerilogLevel)level) |
||||
|
.WriteTo.Trace(outputTemplate: "{Area}: {Message}") |
||||
|
.CreateLogger()); |
||||
|
return builder; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue