mirror of
https://github.com/Ellpeck/ExtremelySimpleLogger.git
synced 2024-11-27 11:58:34 +01:00
Compare commits
No commits in common. "66842eec404cfafa30771618cc2960281af9bb29" and "4d5478bcf2760dab5be330d4632b988c6a64cc66" have entirely different histories.
66842eec40
...
4d5478bcf2
7 changed files with 38 additions and 124 deletions
|
@ -1,19 +0,0 @@
|
|||
steps:
|
||||
build:
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||
commands:
|
||||
- dotnet build **/ExtremelySimpleLogger.csproj
|
||||
pack:
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||
commands:
|
||||
- find . -type f -name '*.nupkg' -delete
|
||||
- dotnet pack **/ExtremelySimpleLogger.csproj --version-suffix ci.$CI_PIPELINE_NUMBER
|
||||
push:
|
||||
when:
|
||||
- event: [push, manual]
|
||||
branch: main
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||
commands:
|
||||
- dotnet nuget push -s https://nuget.ellpeck.de/v3/index.json **/*.nupkg -k $BAGET_KEY -n
|
||||
secrets:
|
||||
- baget_key
|
|
@ -1,10 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace ExtremelySimpleLogger {
|
||||
/// <summary>
|
||||
/// A <see cref="Sink"/> that writes log output to <see cref="Console.Out"/> or <see cref="Console.Error"/>.
|
||||
/// A <see cref="Sink"/> that writes log output to <see cref="Console.Out"/>.
|
||||
/// </summary>
|
||||
public class ConsoleSink : Sink {
|
||||
|
||||
|
@ -18,15 +17,6 @@ namespace ExtremelySimpleLogger {
|
|||
{LogLevel.Fatal, ConsoleColor.DarkRed}
|
||||
};
|
||||
private readonly object locker = new object();
|
||||
private readonly TextWriter console;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new console sink with the given settings.
|
||||
/// </summary>
|
||||
/// <param name="error">Whether to log to <see cref="Console.Error"/> instead of <see cref="Console.Out"/>.</param>
|
||||
public ConsoleSink(bool error = false) {
|
||||
this.console = error ? Console.Error : Console.Out;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="ConsoleColor"/> that text with the given <see cref="LogLevel"/> should be displayed with.
|
||||
|
@ -67,11 +57,11 @@ namespace ExtremelySimpleLogger {
|
|||
var color = this.GetColor(level);
|
||||
if (color.HasValue)
|
||||
Console.ForegroundColor = color.Value;
|
||||
this.console.WriteLine(s);
|
||||
Console.WriteLine(s);
|
||||
if (color.HasValue)
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net45;netstandard2.0;net8.0</TargetFrameworks>
|
||||
<TargetFrameworks>net45;netstandard2.0;net6.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
|||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<PackageIcon>Logo.png</PackageIcon>
|
||||
<VersionPrefix>1.3.3</VersionPrefix>
|
||||
<VersionPrefix>1.3.1</VersionPrefix>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ExtremelySimpleLogger {
|
||||
/// <summary>
|
||||
/// Implementation of a <see cref="TextWriter"/> that writes to a <see cref="Logger"/>.
|
||||
/// </summary>
|
||||
public class LogWriter : TextWriter {
|
||||
|
||||
/// <summary>
|
||||
/// The log level that this log writer should write with.
|
||||
/// </summary>
|
||||
public LogLevel Level {
|
||||
get {
|
||||
lock (this.logger)
|
||||
return this.level;
|
||||
}
|
||||
set {
|
||||
lock (this.logger)
|
||||
this.level = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Encoding Encoding => Encoding.UTF8;
|
||||
|
||||
private readonly StringBuilder line = new StringBuilder();
|
||||
private readonly Logger logger;
|
||||
|
||||
private LogLevel level;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new log writer with the given settings.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger to write to.</param>
|
||||
/// <param name="level">The log level to write with.</param>
|
||||
public LogWriter(Logger logger, LogLevel level = LogLevel.Info) {
|
||||
this.logger = logger;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(char value) {
|
||||
lock (this.logger)
|
||||
this.line.Append(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(char[] buffer, int index, int count) {
|
||||
lock (this.logger)
|
||||
this.line.Append(buffer, index, count);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(string value) {
|
||||
lock (this.logger)
|
||||
this.line.Append(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void WriteLine(string value) {
|
||||
this.Write(value);
|
||||
this.WriteLine();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void WriteLine() {
|
||||
this.Flush();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Flush() {
|
||||
lock (this.logger) {
|
||||
this.logger.Log(this.level, this.line);
|
||||
this.line.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
31
Jenkinsfile
vendored
Normal file
31
Jenkinsfile
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
pipeline {
|
||||
agent any
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
sh 'dotnet build **/ExtremelySimpleLogger.csproj'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Pack') {
|
||||
steps {
|
||||
sh 'find . -type f -name \\\'*.nupkg\\\' -delete'
|
||||
sh 'dotnet pack **/ExtremelySimpleLogger.csproj --version-suffix ${BUILD_NUMBER}'
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish') {
|
||||
when {
|
||||
branch 'main'
|
||||
}
|
||||
steps {
|
||||
sh '''dotnet nuget push -s http://localhost:5000/v3/index.json **/*.nupkg -k $BAGET -n true
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
environment {
|
||||
BAGET = credentials('3db850d0-e6b5-43d5-b607-d180f4eab676')
|
||||
}
|
||||
}
|
|
@ -39,15 +39,9 @@ namespace Sample {
|
|||
logger.Log(LogLevel.Trace, "This is a message that only the file sink will receive, since its minimum level is lower.");
|
||||
logger.Log(LogLevel.Info, "The program finished.");
|
||||
|
||||
// we can also use a writer to write to the log
|
||||
Console.SetError(new LogWriter(logger, LogLevel.Warn));
|
||||
Console.Error.WriteLine("This is an error written through serr! Oh no!");
|
||||
Console.Error.Write("This is another error, but ");
|
||||
Console.Error.WriteLine("written in multiple parts!");
|
||||
|
||||
// Once we're done using the logger, we can dispose it so that our FileSink instances free their files
|
||||
logger.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in a new issue