Skip to content

Commit 7314241

Browse files
committed
#4, support @ destructuring if present in property names (with thanks to @alecor191).
1 parent 7bc6ee6 commit 7314241

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

samples/MvcSample/project.lock.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@
919919
"lib/dnx451/Microsoft.Framework.CodeGenerators.Mvc.dll": {}
920920
}
921921
},
922-
"Microsoft.Framework.CommandLineUtils.Sources/1.0.0-beta5-11749": {
922+
"Microsoft.Framework.CommandLineUtils.Sources/1.0.0-beta5": {
923923
"frameworkAssemblies": [
924924
"mscorlib",
925925
"System",
@@ -2207,10 +2207,10 @@
22072207
"lib/dnxcore50/Microsoft.Framework.CodeGenerators.Mvc.dll": {}
22082208
}
22092209
},
2210-
"Microsoft.Framework.CommandLineUtils.Sources/1.0.0-beta5-11749": {
2210+
"Microsoft.Framework.CommandLineUtils.Sources/1.0.0-beta5": {
22112211
"dependencies": {
2212-
"System.Collections": "4.0.10-beta-22910",
2213-
"System.Runtime": "4.0.20-beta-22910"
2212+
"System.Collections": "4.0.10-beta-23019",
2213+
"System.Runtime": "4.0.20-beta-23019"
22142214
},
22152215
"compile": {
22162216
"lib/dnxcore50/Microsoft.Framework.CommandLineUtils.Sources.dll": {}
@@ -4418,11 +4418,11 @@
44184418
"Templates/ViewGenerator/List.cshtml"
44194419
]
44204420
},
4421-
"Microsoft.Framework.CommandLineUtils.Sources/1.0.0-beta5-11749": {
4422-
"sha512": "p5BKgSXoul11gV8GhsALFF0och8SqajPiVx6QUtYZY9TqVdGbl0t7HAomaRUNQGuaE15W4SNdx3BYiLQFB+WOQ==",
4421+
"Microsoft.Framework.CommandLineUtils.Sources/1.0.0-beta5": {
4422+
"sha512": "sZIlSWm9r2CFDI5JB21lKwa8Hq7DZPBYx3LcBnuxZnhSh2AwrhrS88YUZSMP6QCV+PHMwj0udTdnS1eZ2DbM7w==",
44234423
"files": [
4424-
"Microsoft.Framework.CommandLineUtils.Sources.1.0.0-beta5-11749.nupkg",
4425-
"Microsoft.Framework.CommandLineUtils.Sources.1.0.0-beta5-11749.nupkg.sha512",
4424+
"Microsoft.Framework.CommandLineUtils.Sources.1.0.0-beta5.nupkg",
4425+
"Microsoft.Framework.CommandLineUtils.Sources.1.0.0-beta5.nupkg.sha512",
44264426
"Microsoft.Framework.CommandLineUtils.Sources.nuspec",
44274427
"lib/dnx451/Microsoft.Framework.CommandLineUtils.Sources.dll",
44284428
"lib/dnx451/Microsoft.Framework.CommandLineUtils.Sources.xml",

samples/Sample/Program.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Main(string[] args)
3333
_logger.LogInformation("Starting");
3434

3535
var startTime = DateTimeOffset.UtcNow;
36-
_logger.LogInformation(1, "Started at '{StartTime}' and 0x{Hello:X} is hex of 42", startTime, 42);
36+
_logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
3737

3838
try
3939
{
@@ -51,10 +51,9 @@ public void Main(string[] args)
5151

5252
using (_logger.BeginScope("Main"))
5353
{
54-
Console.WriteLine("Hello World");
55-
5654
_logger.LogInformation("Waiting for user input");
57-
Console.ReadLine();
55+
var key = Console.Read();
56+
_logger.LogInformation("User pressed {@KeyInfo}", new { Key = key, KeyChar = (char)key });
5857
}
5958

6059
var endTime = DateTimeOffset.UtcNow;

src/Serilog.Framework.Logging/SerilogLogger.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,14 @@ public void Log(LogLevel logLevel, int eventId, object state, Exception exceptio
6868
{
6969
messageTemplate = (string)property.Value;
7070
}
71-
else
72-
{
73-
logger = logger.ForContext(property.Key, property.Value);
74-
}
71+
else if (property.Key.StartsWith("@"))
72+
{
73+
logger = logger.ForContext(property.Key.Substring(1), property.Value, destructureObjects: true);
74+
}
75+
else
76+
{
77+
logger = logger.ForContext(property.Key, property.Value);
78+
}
7579
}
7680

7781
var stateType = state.GetType();

src/Serilog.Framework.Logging/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.0-*",
2+
"version": "1.0.0-beta-*",
33
"description": "Serilog provider for Microsoft.Framework.Logging",
44
"authors": [ "Microsoft", "Serilog Contributors" ],
55
"tags": [ "serilog dnx" ],

0 commit comments

Comments
 (0)