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

Add API approval test #142

Merged
merged 1 commit into from
Mar 14, 2023
Merged
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
27 changes: 27 additions & 0 deletions test/Serilog.Sinks.Console.Tests/Approval/ApiApprovalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#if NET5_0

using PublicApiGenerator;
using Shouldly;
using Xunit;

namespace Serilog.Sinks.Console.Tests.Approval
{
public class ApiApprovalTests
{
[Fact]
public void PublicApi_Should_Not_Change_Unintentionally()
{
var assembly = typeof(ConsoleLoggerConfigurationExtensions).Assembly;
var publicApi = assembly.GeneratePublicApi(
new ApiGeneratorOptions()
{
IncludeAssemblyAttributes = false,
ExcludeAttributes = new[] { "System.Diagnostics.DebuggerDisplayAttribute" },
});

publicApi.ShouldMatchApproved(options => options.WithFilenameGenerator((_, __, fileType, fileExtension) => $"{assembly.GetName().Name!}.{fileType}.{fileExtension}"));
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
namespace Serilog
{
public static class ConsoleLoggerConfigurationExtensions
{
public static Serilog.LoggerConfiguration Console(this Serilog.Configuration.LoggerSinkConfiguration sinkConfiguration, Serilog.Formatting.ITextFormatter formatter, Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0, Serilog.Core.LoggingLevelSwitch? levelSwitch = null, Serilog.Events.LogEventLevel? standardErrorFromLevel = default, object? syncRoot = null) { }
public static Serilog.LoggerConfiguration Console(this Serilog.Configuration.LoggerSinkConfiguration sinkConfiguration, Serilog.Events.LogEventLevel restrictedToMinimumLevel = 0, string outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}", System.IFormatProvider? formatProvider = null, Serilog.Core.LoggingLevelSwitch? levelSwitch = null, Serilog.Events.LogEventLevel? standardErrorFromLevel = default, Serilog.Sinks.SystemConsole.Themes.ConsoleTheme? theme = null, bool applyThemeToRedirectedOutput = false, object? syncRoot = null) { }
}
}
namespace Serilog.Sinks.SystemConsole.Themes
{
public class AnsiConsoleTheme : Serilog.Sinks.SystemConsole.Themes.ConsoleTheme
{
public AnsiConsoleTheme(System.Collections.Generic.IReadOnlyDictionary<Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle, string> styles) { }
public override bool CanBuffer { get; }
protected override int ResetCharCount { get; }
public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Code { get; }
public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Grayscale { get; }
public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Literate { get; }
public static Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme Sixteen { get; }
public override void Reset(System.IO.TextWriter output) { }
public override int Set(System.IO.TextWriter output, Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle style) { }
}
public abstract class ConsoleTheme
{
protected ConsoleTheme() { }
public abstract bool CanBuffer { get; }
protected abstract int ResetCharCount { get; }
public static Serilog.Sinks.SystemConsole.Themes.ConsoleTheme None { get; }
public abstract void Reset(System.IO.TextWriter output);
public abstract int Set(System.IO.TextWriter output, Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle style);
}
public enum ConsoleThemeStyle
{
Text = 0,
SecondaryText = 1,
TertiaryText = 2,
Invalid = 3,
Null = 4,
Name = 5,
String = 6,
Number = 7,
Boolean = 8,
Scalar = 9,
[System.Obsolete("Use ConsoleThemeStyle.Scalar instead")]
Object = 9,
LevelVerbose = 10,
LevelDebug = 11,
LevelInformation = 12,
LevelWarning = 13,
LevelError = 14,
LevelFatal = 15,
}
public class SystemConsoleTheme : Serilog.Sinks.SystemConsole.Themes.ConsoleTheme
{
public SystemConsoleTheme(System.Collections.Generic.IReadOnlyDictionary<Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle, Serilog.Sinks.SystemConsole.Themes.SystemConsoleThemeStyle> styles) { }
public override bool CanBuffer { get; }
protected override int ResetCharCount { get; }
public System.Collections.Generic.IReadOnlyDictionary<Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle, Serilog.Sinks.SystemConsole.Themes.SystemConsoleThemeStyle> Styles { get; }
public static Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme Colored { get; }
public static Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme Grayscale { get; }
public static Serilog.Sinks.SystemConsole.Themes.SystemConsoleTheme Literate { get; }
public override void Reset(System.IO.TextWriter output) { }
public override int Set(System.IO.TextWriter output, Serilog.Sinks.SystemConsole.Themes.ConsoleThemeStyle style) { }
}
public struct SystemConsoleThemeStyle
{
public System.ConsoleColor? Background;
public System.ConsoleColor? Foreground;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp2.2;netcoreapp3.0;netcoreapp3.1;net452;net462;net472;net48;net5.0</TargetFrameworks>
Expand All @@ -19,6 +19,8 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="PublicApiGenerator" Version="11.0.0" Condition="'$(TargetFramework)' == 'net5.0'" />
</ItemGroup>

</Project>