Skip to content

Commit 16befd3

Browse files
committed
Merge pull request #19 from runxc1/dev
First Pass at getting Serilog to work with ASP.Net 5 RC1
2 parents 798d954 + ab9e43f commit 16befd3

File tree

13 files changed

+7124
-5518
lines changed

13 files changed

+7124
-5518
lines changed

global.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
{
2-
"projects": [ "src", "test" ],
3-
"sdk": {
4-
"version": "1.0.0-beta8"
5-
}
6-
}
1+
{
2+
"projects": [ "src", "test" ],
3+
"sdk": {
4+
"version": "1.0.0-rc1-final"
5+
}
6+
}

samples/Sample/Program.cs

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
using System;
2-
using Microsoft.Framework.Logging;
3-
using ILogger = Microsoft.Framework.Logging.ILogger;
4-
using Serilog;
5-
6-
namespace Sample
7-
{
8-
public class Program
9-
{
10-
private readonly ILogger _logger;
11-
12-
public Program()
13-
{
14-
Log.Logger = new LoggerConfiguration()
15-
.MinimumLevel.Debug()
16-
#if DNXCORE50
17-
.WriteTo.TextWriter(Console.Out)
18-
#else
19-
.Enrich.WithMachineName()
20-
.Enrich.WithProcessId()
21-
.Enrich.WithThreadId()
22-
.WriteTo.ColoredConsole()
23-
#endif
24-
.CreateLogger();
25-
26-
_logger = new LoggerFactory()
27-
.AddSerilog()
28-
.CreateLogger(typeof(Program).FullName);
29-
}
30-
31-
public void Main(string[] args)
32-
{
33-
_logger.LogInformation("Starting");
34-
35-
var startTime = DateTimeOffset.UtcNow;
36-
_logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
37-
38-
try
39-
{
40-
throw new Exception("Boom");
41-
}
42-
catch (Exception ex)
43-
{
44-
_logger.LogCritical("Unexpected critical error starting application", ex);
45-
_logger.Log(LogLevel.Critical, 0, "Unexpected critical error", ex, null);
46-
// This write should not log anything
47-
_logger.Log(LogLevel.Critical, 0, null, null, null);
48-
_logger.LogError("Unexpected error", ex);
49-
_logger.LogWarning("Unexpected warning", ex);
50-
}
51-
52-
using (_logger.BeginScope("Main"))
53-
{
54-
_logger.LogInformation("Waiting for user input");
55-
var key = Console.Read();
56-
_logger.LogInformation("User pressed {@KeyInfo}", new { Key = key, KeyChar = (char)key });
57-
}
58-
59-
var endTime = DateTimeOffset.UtcNow;
60-
_logger.LogInformation(2, "Stopping at {StopTime}", endTime);
61-
62-
_logger.LogInformation("Stopping");
63-
64-
_logger.LogInformation(Environment.NewLine);
65-
_logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "RESULT", "START TIME", "END TIME", "DURATION(ms)");
66-
_logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "------", "----- ----", "--- ----", "------------");
67-
_logger.LogInformation("{Result,-10:l}{StartTime,15:mm:s tt}{EndTime,15:mm:s tt}{Duration,15}", "SUCCESS", startTime, endTime, (endTime - startTime).TotalMilliseconds);
68-
}
69-
}
70-
}
1+
using System;
2+
using Microsoft.Extensions.Logging;
3+
using ILogger = Microsoft.Extensions.Logging.ILogger;
4+
using Serilog;
5+
6+
namespace Sample
7+
{
8+
public class Program
9+
{
10+
private readonly ILogger _logger;
11+
12+
public Program()
13+
{
14+
Log.Logger = new LoggerConfiguration()
15+
.MinimumLevel.Debug()
16+
#if DNXCORE50
17+
.WriteTo.TextWriter(Console.Out)
18+
#else
19+
.Enrich.WithMachineName()
20+
.Enrich.WithProcessId()
21+
.Enrich.WithThreadId()
22+
.WriteTo.ColoredConsole()
23+
#endif
24+
.CreateLogger();
25+
26+
_logger = new LoggerFactory()
27+
.AddSerilog()
28+
.CreateLogger(typeof(Program).FullName);
29+
}
30+
31+
public void Main(string[] args)
32+
{
33+
_logger.LogInformation("Starting");
34+
35+
var startTime = DateTimeOffset.UtcNow;
36+
_logger.LogInformation(1, "Started at {StartTime} and 0x{Hello:X} is hex of 42", startTime, 42);
37+
38+
try
39+
{
40+
throw new Exception("Boom");
41+
}
42+
catch (Exception ex)
43+
{
44+
_logger.LogCritical("Unexpected critical error starting application", ex);
45+
_logger.Log(LogLevel.Critical, 0, "Unexpected critical error", ex, null);
46+
// This write should not log anything
47+
_logger.Log(LogLevel.Critical, 0, null, null, null);
48+
_logger.LogError("Unexpected error", ex);
49+
_logger.LogWarning("Unexpected warning", ex);
50+
}
51+
52+
using (_logger.BeginScope("Main"))
53+
{
54+
_logger.LogInformation("Waiting for user input");
55+
var key = Console.Read();
56+
_logger.LogInformation("User pressed {@KeyInfo}", new { Key = key, KeyChar = (char)key });
57+
}
58+
59+
var endTime = DateTimeOffset.UtcNow;
60+
_logger.LogInformation(2, "Stopping at {StopTime}", endTime);
61+
62+
_logger.LogInformation("Stopping");
63+
64+
_logger.LogInformation(Environment.NewLine);
65+
_logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "RESULT", "START TIME", "END TIME", "DURATION(ms)");
66+
_logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "------", "----- ----", "--- ----", "------------");
67+
_logger.LogInformation("{Result,-10:l}{StartTime,15:mm:s tt}{EndTime,15:mm:s tt}{Duration,15}", "SUCCESS", startTime, endTime, (endTime - startTime).TotalMilliseconds);
68+
}
69+
}
70+
}

samples/Sample/project.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"licenseUrl": "",
88

99
"dependencies": {
10-
"Microsoft.Framework.Logging": "1.0.0-beta8",
1110
"Serilog.Framework.Logging": "1.0.0-*"
1211
},
1312

@@ -19,11 +18,11 @@
1918
"dnx451": {},
2019
"dnxcore50": {
2120
"dependencies": {
22-
"System.Console": "4.0.0-beta-23019",
23-
"System.Collections": "4.0.10-beta-23019",
24-
"System.Linq": "4.0.0-beta-23019",
25-
"System.Threading": "4.0.10-beta-23019",
26-
"Microsoft.CSharp": "4.0.0-beta-23019"
21+
"System.Console": "4.0.0-beta-23516",
22+
"System.Collections": "4.0.0",
23+
"System.Linq": "4.0.0",
24+
"System.Threading": "4.0.0",
25+
"Microsoft.CSharp": "4.0.0"
2726
}
2827
}
2928
}

0 commit comments

Comments
 (0)