-
Notifications
You must be signed in to change notification settings - Fork 131
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 #377 from nblumhardt/v7
v7.0 - pin to MEC v7, including matching target frameworks
- Loading branch information
Showing
16 changed files
with
129 additions
and
116 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
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,21 @@ | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Sample; | ||
|
||
// The filter syntax in the sample configuration file is | ||
// processed by the Serilog.Filters.Expressions package. | ||
public class CustomFilter : ILogEventFilter | ||
{ | ||
readonly LogEventLevel _levelFilter; | ||
|
||
public CustomFilter(LogEventLevel levelFilter = LogEventLevel.Information) | ||
{ | ||
_levelFilter = levelFilter; | ||
} | ||
|
||
public bool IsEnabled(LogEvent logEvent) | ||
{ | ||
return logEvent.Level >= _levelFilter; | ||
} | ||
} |
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,24 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Sample; | ||
|
||
public class CustomPolicy : IDestructuringPolicy | ||
{ | ||
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result) | ||
{ | ||
result = null; | ||
|
||
if (value is LoginData loginData) | ||
{ | ||
result = new StructureValue( | ||
new List<LogEventProperty> | ||
{ | ||
new("Username", new ScalarValue(loginData.Username)) | ||
}); | ||
} | ||
|
||
return (result != null); | ||
} | ||
} |
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,8 @@ | ||
namespace Sample; | ||
|
||
public class LoginData | ||
{ | ||
public string? Username; | ||
// ReSharper disable once NotAccessedField.Global | ||
public string? Password; | ||
} |
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,98 +1,46 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
using Sample; | ||
using Serilog; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
using Serilog.Debugging; | ||
|
||
// ReSharper disable UnusedType.Global | ||
|
||
namespace Sample; | ||
|
||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
SelfLog.Enable(Console.Error); | ||
|
||
Thread.CurrentThread.Name = "Main thread"; | ||
|
||
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) | ||
.Build(); | ||
|
||
var logger = new LoggerConfiguration() | ||
.ReadFrom.Configuration(configuration) | ||
.CreateLogger(); | ||
|
||
logger.Information("Args: {Args}", args); | ||
|
||
do | ||
{ | ||
logger.ForContext<Program>().Information("Hello, world!"); | ||
logger.ForContext<Program>().Error("Hello, world!"); | ||
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Warning("Hello, world!"); | ||
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Error("Hello, world!"); | ||
logger.ForContext(Constants.SourceContextPropertyName, "MyApp.Something.Tricky").Verbose("Hello, world!"); | ||
SelfLog.Enable(Console.Error); | ||
|
||
logger.Information("Destructure with max object nesting depth:\n{@NestedObject}", | ||
new { FiveDeep = new { Two = new { Three = new { Four = new { Five = "the end" } } } } }); | ||
Thread.CurrentThread.Name = "Main thread"; | ||
|
||
logger.Information("Destructure with max string length:\n{@LongString}", | ||
new { TwentyChars = "0123456789abcdefghij" }); | ||
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) | ||
.Build(); | ||
|
||
logger.Information("Destructure with max collection count:\n{@BigData}", | ||
new { TenItems = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" } }); | ||
var logger = new LoggerConfiguration() | ||
.ReadFrom.Configuration(configuration) | ||
.CreateLogger(); | ||
|
||
logger.Information("Destructure with policy to strip password:\n{@LoginData}", | ||
new LoginData { Username = "BGates", Password = "isityearoflinuxyet" }); | ||
logger.Information("Args: {Args}", args); | ||
|
||
Console.WriteLine("\nPress \"q\" to quit, or any other key to run again.\n"); | ||
} | ||
while (!args.Contains("--run-once") && (Console.ReadKey().KeyChar != 'q')); | ||
} | ||
} | ||
|
||
// The filter syntax in the sample configuration file is | ||
// processed by the Serilog.Filters.Expressions package. | ||
public class CustomFilter : ILogEventFilter | ||
do | ||
{ | ||
readonly LogEventLevel _levelFilter; | ||
logger.ForContext<Program>().Information("Hello, world!"); | ||
logger.ForContext<Program>().Error("Hello, world!"); | ||
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Warning("Hello, world!"); | ||
logger.ForContext(Constants.SourceContextPropertyName, "Microsoft").Error("Hello, world!"); | ||
logger.ForContext(Constants.SourceContextPropertyName, "MyApp.Something.Tricky").Verbose("Hello, world!"); | ||
|
||
public CustomFilter(LogEventLevel levelFilter = LogEventLevel.Information) | ||
{ | ||
_levelFilter = levelFilter; | ||
} | ||
logger.Information("Destructure with max object nesting depth:\n{@NestedObject}", | ||
new { FiveDeep = new { Two = new { Three = new { Four = new { Five = "the end" } } } } }); | ||
|
||
public bool IsEnabled(LogEvent logEvent) | ||
{ | ||
return logEvent.Level >= _levelFilter; | ||
} | ||
} | ||
logger.Information("Destructure with max string length:\n{@LongString}", | ||
new { TwentyChars = "0123456789abcdefghij" }); | ||
|
||
public class LoginData | ||
{ | ||
public string? Username; | ||
// ReSharper disable once NotAccessedField.Global | ||
public string? Password; | ||
} | ||
|
||
public class CustomPolicy : IDestructuringPolicy | ||
{ | ||
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, out LogEventPropertyValue? result) | ||
{ | ||
result = null; | ||
logger.Information("Destructure with max collection count:\n{@BigData}", | ||
new { TenItems = new[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" } }); | ||
|
||
if (value is LoginData loginData) | ||
{ | ||
result = new StructureValue( | ||
new List<LogEventProperty> | ||
{ | ||
new("Username", new ScalarValue(loginData.Username)) | ||
}); | ||
} | ||
logger.Information("Destructure with policy to strip password:\n{@LoginData}", | ||
new LoginData { Username = "BGates", Password = "isityearoflinuxyet" }); | ||
|
||
return (result != null); | ||
} | ||
Console.WriteLine("\nPress \"q\" to quit, or any other key to run again.\n"); | ||
} | ||
while (!args.Contains("--run-once") && (Console.ReadKey().KeyChar != 'q')); |
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
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
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
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
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
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
Oops, something went wrong.