Skip to content

Commit db82f98

Browse files
committed
Rename to Serilog.Extensions.Logging; update Serilog dependency version.
1 parent e2762e1 commit db82f98

16 files changed

+69
-73
lines changed

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
# Serilog.Framework.Logging
2-
[![Build status](https://ci.appveyor.com/api/projects/status/865nohxfiq1rnby0/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-framework-logging/branch/master) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Framework.Logging.svg?style=flat)](https://www.nuget.org/packages/Serilog.Framework.Logging/)
1+
# Serilog.Extensions.Logging
2+
[![Build status](https://ci.appveyor.com/api/projects/status/865nohxfiq1rnby0/branch/master?svg=true)](https://ci.appveyor.com/project/serilog/serilog-extensions-logging/branch/master) [![NuGet Version](http://img.shields.io/nuget/v/Serilog.Extensions.Logging.svg?style=flat)](https://www.nuget.org/packages/Serilog.Extensions.Logging/)
33

44

5-
A serilog provider for [Microsoft.Extensions.Logging](https://www.nuget.org/packages/Microsoft.Extensions.Logging), the logging subsystem used by ASP.NET 5. (Previously known as [Microsoft.Framework.Logging](https://github.com/aspnet/Logging/issues/257)).
5+
A Serilog provider for [Microsoft.Extensions.Logging](https://www.nuget.org/packages/Microsoft.Extensions.Logging), the logging subsystem used by ASP.NET 5.
66

77
This package routes ASP.NET log messages through Serilog, so you can get information about ASP.NET's internal operations logged to the same Serilog sinks as your application events.
88

99
### Instructions
1010

11-
**First**, install the _Serilog.Framework.Logging_ [NuGet package](https://www.nuget.org/packages/Serilog.Framework.Logging) into your web or console app.
11+
**First**, install the _Serilog.Extensions.Logging_ [NuGet package](https://www.nuget.org/packages/Serilog.Extensions.Logging) into your web or console app. You will need a way to view the log messages - _Serilog.Sinks.Literate_ writes these to the console.
12+
13+
```powershell
14+
Install-Package Serilog.Extensions.Logging
15+
Install-Package Serilog.Sinks.Literate
16+
```
1217

1318
**Next**, in your application's `Startup` method, configure Serilog first:
1419

@@ -20,14 +25,12 @@ public class Startup
2025
public Startup(IHostingEnvironment env)
2126
{
2227
Log.Logger = new LoggerConfiguration()
23-
.WriteTo.Console()
28+
.WriteTo.LiterateConsole()
2429
.CreateLogger();
2530

2631
// Other startup code
2732
```
2833

29-
The conditional compilation (`#if`) is necessary if you're targeting the CoreCLR runtime, for which there are currenlty few Serilog sinks. If you're targeting the full .NET framework you can just use `.WriteTo.Trace()`, or any other available sink.
30-
3134
**Finally**, in your `Startup` class's `Configure()` method, call `AddSerilog()` on the provided `loggerFactory`.
3235

3336
```csharp
@@ -41,16 +44,16 @@ The conditional compilation (`#if`) is necessary if you're targeting the CoreCLR
4144
That's it! With the level bumped up a little you should see log output like:
4245

4346
```
44-
2015-05-15 22:14:44.646 +10:00 [Debug] RouteCollection.RouteAsync
47+
2015-05-15 22:14:44.646 +10:00 [DBG] RouteCollection.RouteAsync
4548
Routes:
4649
Microsoft.AspNet.Mvc.Routing.AttributeRoute
4750
{controller=Home}/{action=Index}/{id?}
4851
Handled? True
49-
2015-05-15 22:14:44.647 +10:00 [Debug] RouterMiddleware.Invoke
52+
2015-05-15 22:14:44.647 +10:00 [DBG] RouterMiddleware.Invoke
5053
Handled? True
51-
2015-05-15 22:14:45.706 +10:00 [Debug] /lib/jquery/jquery.js not modified
52-
2015-05-15 22:14:45.706 +10:00 [Debug] /css/site.css not modified
53-
2015-05-15 22:14:45.741 +10:00 [Debug] Handled. Status code: 304 File: /css/site.css
54+
2015-05-15 22:14:45.706 +10:00 [DBG] /lib/jquery/jquery.js not modified
55+
2015-05-15 22:14:45.706 +10:00 [DBG] /css/site.css not modified
56+
2015-05-15 22:14:45.741 +10:00 [DBG] Handled. Status code: 304 File: /css/site.css
5457
```
5558

5659
### Levels

samples/Sample/Program.cs

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,57 @@
11
using System;
22
using Microsoft.Extensions.Logging;
3-
using ILogger = Microsoft.Extensions.Logging.ILogger;
43
using Serilog;
54

65
namespace Sample
76
{
8-
public class Program
7+
public static class Program
98
{
10-
private readonly ILogger _logger;
11-
12-
public Program()
9+
public static void Main(string[] args)
1310
{
1411
Log.Logger = new LoggerConfiguration()
1512
.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
13+
.WriteTo.LiterateConsole()
2414
.CreateLogger();
2515

26-
_logger = new LoggerFactory()
16+
var logger = new LoggerFactory()
2717
.AddSerilog()
2818
.CreateLogger(typeof(Program).FullName);
29-
}
3019

31-
public void Main(string[] args)
32-
{
33-
_logger.LogInformation("Starting");
20+
logger.LogInformation("Starting");
3421

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

3825
try
3926
{
4027
throw new Exception("Boom");
4128
}
4229
catch (Exception ex)
4330
{
44-
_logger.LogCritical("Unexpected critical error starting application", ex);
45-
_logger.Log(LogLevel.Critical, 0, "Unexpected critical error", ex, null);
31+
logger.LogCritical("Unexpected critical error starting application", ex);
32+
logger.Log(LogLevel.Critical, 0, "Unexpected critical error", ex, null);
4633
// 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);
34+
logger.Log(LogLevel.Critical, 0, null, null, null);
35+
logger.LogError("Unexpected error", ex);
36+
logger.LogWarning("Unexpected warning", ex);
5037
}
5138

52-
using (_logger.BeginScope("Main"))
39+
using (logger.BeginScope("Main"))
5340
{
54-
_logger.LogInformation("Waiting for user input");
41+
logger.LogInformation("Waiting for user input");
5542
var key = Console.Read();
56-
_logger.LogInformation("User pressed {@KeyInfo}", new { Key = key, KeyChar = (char)key });
43+
logger.LogInformation("User pressed {@KeyInfo}", new { Key = key, KeyChar = (char)key });
5744
}
5845

5946
var endTime = DateTimeOffset.UtcNow;
60-
_logger.LogInformation(2, "Stopping at {StopTime}", endTime);
47+
logger.LogInformation(2, "Stopping at {StopTime}", endTime);
6148

62-
_logger.LogInformation("Stopping");
49+
logger.LogInformation("Stopping");
6350

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);
51+
logger.LogInformation(Environment.NewLine);
52+
logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "RESULT", "START TIME", "END TIME", "DURATION(ms)");
53+
logger.LogInformation("{Result,-10:l}{StartTime,15:l}{EndTime,15:l}{Duration,15:l}", "------", "----- ----", "--- ----", "------------");
54+
logger.LogInformation("{Result,-10:l}{StartTime,15:mm:s tt}{EndTime,15:mm:s tt}{Duration,15}", "SUCCESS", startTime, endTime, (endTime - startTime).TotalMilliseconds);
6855
}
6956
}
7057
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"profiles": {}
3+
}

samples/Sample/Sample.xproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
55
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
66
</PropertyGroup>
7-
87
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
98
<PropertyGroup Label="Globals">
109
<ProjectGuid>65357fbc-9bc4-466d-b621-1c3a19bc2a78</ProjectGuid>
1110
<RootNamespace>Sample</RootNamespace>
1211
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
1312
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
1413
</PropertyGroup>
15-
1614
<PropertyGroup>
1715
<SchemaVersion>2.0</SchemaVersion>
1816
</PropertyGroup>
17+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
1918
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
20-
</Project>
19+
</Project>

samples/Sample/project.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@
55
"tags": [ "" ],
66
"projectUrl": "",
77
"licenseUrl": "",
8-
8+
"compilationOptions": {
9+
"emitEntryPoint": true
10+
},
911
"dependencies": {
10-
"Serilog.Framework.Logging": "1.0.0-*"
12+
"Serilog.Extensions.Logging": "1.0.0-*",
13+
"Serilog.Sinks.Literate": "2.0.0-beta-21"
1114
},
1215

1316
"commands": {
1417
"Sample": "Sample"
1518
},
1619

1720
"frameworks": {
18-
"dnx451": {},
21+
"dnx451": { },
1922
"dnxcore50": {
2023
"dependencies": {
24+
"Microsoft.CSharp": "4.0.1-beta-23516",
25+
"System.Collections": "4.0.11-beta-23516",
2126
"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"
27+
"System.Linq": "4.0.1-beta-23516",
28+
"System.Threading": "4.0.11-beta-23516"
2629
}
2730
}
2831
}

serilog-framework-logging.sln renamed to serilog-extensions-logging.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ VisualStudioVersion = 14.0.22823.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0}"
77
EndProject
8-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Framework.Logging", "src\Serilog.Framework.Logging\Serilog.Framework.Logging.xproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}"
8+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Extensions.Logging", "src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.xproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}"
99
EndProject
10-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Framework.Logging.Tests", "test\Serilog.Framework.Logging.Tests\Serilog.Framework.Logging.Tests.xproj", "{37EADF84-5E41-4224-A194-1E3299DCD0B8}"
10+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Extensions.Logging.Tests", "test\Serilog.Extensions.Logging.Tests\Serilog.Extensions.Logging.Tests.xproj", "{37EADF84-5E41-4224-A194-1E3299DCD0B8}"
1111
EndProject
1212
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}"
1313
EndProject

src/Serilog.Framework.Logging/SerilogLogger.cs renamed to src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using System.Reflection;
1111
using Serilog.Parsing;
1212

13-
namespace Serilog.Framework.Logging
13+
namespace Serilog.Extensions.Logging
1414
{
1515
public class SerilogLogger : FrameworkLogger
1616
{

src/Serilog.Framework.Logging/SerilogLoggerProvider.cs renamed to src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using Serilog.Events;
1414
using FrameworkLogger = Microsoft.Extensions.Logging.ILogger;
1515

16-
namespace Serilog.Framework.Logging
16+
namespace Serilog.Extensions.Logging
1717
{
1818
public class SerilogLoggerProvider : ILoggerProvider, ILogEventEnricher
1919
{

src/Serilog.Framework.Logging/SerilogLoggerScope.cs renamed to src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55

6-
namespace Serilog.Framework.Logging
6+
namespace Serilog.Extensions.Logging
77
{
88
public class SerilogLoggerScope : IDisposable
99
{

src/Serilog.Framework.Logging/Serilog.Framework.Logging.xproj renamed to src/Serilog.Extensions.Logging/Serilog.Extensions.Logging.xproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
88
<PropertyGroup Label="Globals">
99
<ProjectGuid>903cd13a-d54b-4cec-a55f-e22ae3d93b3b</ProjectGuid>
10-
<RootNamespace>Serilog.Framework.Logging</RootNamespace>
10+
<RootNamespace>Serilog</RootNamespace>
1111
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
1212
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
1313
</PropertyGroup>

0 commit comments

Comments
 (0)