-
Notifications
You must be signed in to change notification settings - Fork 0
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 #9 from dotnet-campus/t/lindexi/LogAbstractions
加上抽象的日志
- Loading branch information
Showing
7 changed files
with
247 additions
and
47 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
35 changes: 0 additions & 35 deletions
35
src/dotnetCampus.FileLogger/dotnetCampus.FileLogger/Program.cs
This file was deleted.
Oops, something went wrong.
7 changes: 3 additions & 4 deletions
7
src/dotnetCampus.FileLogger/dotnetCampus.FileLogger/dotnetCampus.FileLogger.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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="dotnetCampus.AsyncWorkerCollection" Version="1.5.2" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="dotnetCampus.AsyncWorkerCollection" Version="1.6.2" /> | ||
</ItemGroup> | ||
</Project> |
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,103 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace dotnetCampus.Logger.Abstractions | ||
{ | ||
/// <summary> | ||
/// Identifies a logging event. The primary identifier is the "Id" property, with the "Name" property providing a short description of this type of event. | ||
/// </summary> | ||
/// Copy from dotnet runtime | ||
#if LogPublicAsInternal | ||
internal | ||
#else | ||
public | ||
#endif | ||
readonly struct EventId | ||
{ | ||
/// <summary> | ||
/// Implicitly creates an EventId from the given <see cref="int"/>. | ||
/// </summary> | ||
/// <param name="i">The <see cref="int"/> to convert to an EventId.</param> | ||
public static implicit operator EventId(int i) | ||
{ | ||
return new EventId(i); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if two specified <see cref="EventId"/> instances have the same value. They are equal if they have the same Id. | ||
/// </summary> | ||
/// <param name="left">The first <see cref="EventId"/>.</param> | ||
/// <param name="right">The second <see cref="EventId"/>.</param> | ||
/// <returns><see langword="true" /> if the objects are equal.</returns> | ||
public static bool operator ==(EventId left, EventId right) | ||
{ | ||
return left.Equals(right); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if two specified <see cref="EventId"/> instances have different values. | ||
/// </summary> | ||
/// <param name="left">The first <see cref="EventId"/>.</param> | ||
/// <param name="right">The second <see cref="EventId"/>.</param> | ||
/// <returns><see langword="true" /> if the objects are not equal.</returns> | ||
public static bool operator !=(EventId left, EventId right) | ||
{ | ||
return !left.Equals(right); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes an instance of the <see cref="EventId"/> struct. | ||
/// </summary> | ||
/// <param name="id">The numeric identifier for this event.</param> | ||
/// <param name="name">The name of this event.</param> | ||
public EventId(int id, string? name = null) | ||
{ | ||
Id = id; | ||
Name = name; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the numeric identifier for this event. | ||
/// </summary> | ||
public int Id { get; } | ||
|
||
/// <summary> | ||
/// Gets the name of this event. | ||
/// </summary> | ||
public string? Name { get; } | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() | ||
{ | ||
return Name ?? Id.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Indicates whether the current object is equal to another object of the same type. Two events are equal if they have the same id. | ||
/// </summary> | ||
/// <param name="other">An object to compare with this object.</param> | ||
/// <returns><see langword="true" /> if the current object is equal to the other parameter; otherwise, <see langword="false" />.</returns> | ||
public bool Equals(EventId other) | ||
{ | ||
return Id == other.Id; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object? obj) | ||
{ | ||
if (obj is null) | ||
{ | ||
return false; | ||
} | ||
|
||
return obj is EventId eventId && Equals(eventId); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() | ||
{ | ||
return Id; | ||
} | ||
} | ||
} |
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,28 @@ | ||
using System; | ||
|
||
namespace dotnetCampus.Logger.Abstractions | ||
{ | ||
/// <summary> | ||
/// Represents a type used to perform logging. | ||
/// </summary> | ||
/// <remarks>Aggregates most logging patterns to a single method.</remarks> | ||
/// Copy from dotnet runtime | ||
#if LogPublicAsInternal | ||
internal | ||
#else | ||
public | ||
#endif | ||
interface ILogger | ||
{ | ||
/// <summary> | ||
/// Writes a log entry. | ||
/// </summary> | ||
/// <param name="logLevel">Entry will be written on this level.</param> | ||
/// <param name="eventId">Id of the event.</param> | ||
/// <param name="state">The entry to be written. Can be also an object.</param> | ||
/// <param name="exception">The exception related to this entry.</param> | ||
/// <param name="formatter">Function to create a <see cref="string"/> message of the <paramref name="state"/> and <paramref name="exception"/>.</param> | ||
/// <typeparam name="TState">The type of the object to be written.</typeparam> | ||
void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter); | ||
} | ||
} |
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,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace dotnetCampus.Logger.Abstractions | ||
{ | ||
/// <summary> | ||
/// Defines logging severity levels. | ||
/// </summary> | ||
/// Copy from dotnet runtime | ||
#if LogPublicAsInternal | ||
internal | ||
#else | ||
public | ||
#endif | ||
enum LogLevel | ||
{ | ||
/// <summary> | ||
/// Logs that contain the most detailed messages. These messages may contain sensitive application data. | ||
/// These messages are disabled by default and should never be enabled in a production environment. | ||
/// </summary> | ||
Trace = 0, | ||
|
||
/// <summary> | ||
/// Logs that are used for interactive investigation during development. These logs should primarily contain | ||
/// information useful for debugging and have no long-term value. | ||
/// </summary> | ||
Debug = 1, | ||
|
||
/// <summary> | ||
/// Logs that track the general flow of the application. These logs should have long-term value. | ||
/// </summary> | ||
Information = 2, | ||
|
||
/// <summary> | ||
/// Logs that highlight an abnormal or unexpected event in the application flow, but do not otherwise cause the | ||
/// application execution to stop. | ||
/// </summary> | ||
Warning = 3, | ||
|
||
/// <summary> | ||
/// Logs that highlight when the current flow of execution is stopped due to a failure. These should indicate a | ||
/// failure in the current activity, not an application-wide failure. | ||
/// </summary> | ||
Error = 4, | ||
|
||
/// <summary> | ||
/// Logs that describe an unrecoverable application or system crash, or a catastrophic failure that requires | ||
/// immediate attention. | ||
/// </summary> | ||
Critical = 5, | ||
|
||
/// <summary> | ||
/// Not used for writing log messages. Specifies that a logging category should not write any messages. | ||
/// </summary> | ||
None = 6, | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/dotnetCampus.Logger.Abstractions/dotnetCampus.Logger.Abstractions.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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp3.1;net45;net5.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="dotnetCampus.SourceYard" Version="0.1.19369-alpha"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |