Skip to content

3.1.0 Release #140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4871096
Sample conversion WIP
nblumhardt Aug 18, 2019
be6b75c
Update the example projects to .NET Core 3.0 conventions
nblumhardt Aug 18, 2019
ba4f44e
Install SDK in Setup.ps1
nblumhardt Aug 19, 2019
7740fbe
Dev version bump [skip ci]
nblumhardt Aug 28, 2019
11bdd7e
Adding source context for the logging in RequestLoggingMiddleware. Fi…
adamlith Sep 3, 2019
64924c4
Merge pull request #124 from adamlith/feature/source-context-in-reque…
nblumhardt Sep 3, 2019
77c2c1a
Changes are now tracked through /releases; no need for CHANGES.md [sk…
nblumhardt Sep 9, 2019
5341d20
FEATURE: add ability to customize the LogEventLevel used by the middl…
Sep 17, 2019
f35e12e
FEATURE: update sdk version to target latest stable .net core SDK
Sep 17, 2019
beab81c
FIX: rollback sdk version to fix the ci
Sep 17, 2019
740fc2f
REFACTORING: removed explicit private to stay consistent with coding …
Sep 18, 2019
d477514
FIX: modified GetLevel to accept both HttpContext and Exception. This…
Sep 20, 2019
390fa72
Update docs on disabling built-in logging
davidcoghlan Sep 25, 2019
e6e14e6
Merge pull request #136 from DavidCoghlan/patch-1
nblumhardt Sep 25, 2019
25af04c
Merge pull request #132 from seroche/dev
nblumhardt Oct 2, 2019
b03e957
Use the final 3.0.100 SDK
nblumhardt Oct 2, 2019
dfbbcae
Merge branch 'dev' into updated-examples
nblumhardt Oct 2, 2019
ed55d3d
Include 'double elapsedMs' in the function signature of the GetLevel …
nblumhardt Oct 2, 2019
47a5d0a
Merge pull request #111 from serilog/updated-examples
nblumhardt Oct 2, 2019
39473b8
Fix a typo in README.md
sgbj Oct 2, 2019
af412ee
Minor version bump, new features coming
nblumhardt Oct 7, 2019
731e583
Merge pull request #138 from sgbj/patch-1
nblumhardt Oct 7, 2019
ac78f96
Slight reformatting of DefaultGetLevel
nblumhardt Oct 7, 2019
2d741c1
Merge pull request #137 from serilog/get-level-elapsed
nblumhardt Oct 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CHANGES.md

This file was deleted.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ Or [as JSON](https://github.com/serilog/serilog-formatting-compact):
}
```

To enable the middleware, first change the minimum level for `Microsoft` to `Warning` in your logger configuration or _appsettings.json_ file:
To enable the middleware, first change the minimum level for `Microsoft.AspNetCore` to `Warning` in your logger configuration or _appsettings.json_ file:

```csharp
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
```

Then, in your application's _Startup.cs_, add the middleware with `UseSerilogRequestLogging()`:
Expand Down Expand Up @@ -205,7 +205,7 @@ Finally, pass the provider collection into `UseSerilog()`:

Providers registered in _Startup.cs_ with `AddLogging()` will then receive events from Serilog.

**Using iniline initialization:**
**Using inline initialization:**

If [inline initialization](#inline-initialization) is used, providers can be enabled by adding `writeToProviders: true` to the `UseSerilog()` method call:

Expand Down
11 changes: 11 additions & 0 deletions Setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ErrorActionPreference = "Stop"

$RequiredDotnetVersion = $(cat ./global.json | convertfrom-json).sdk.version

mkdir "./build"

Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./build/installcli.ps1"
& ./build/installcli.ps1 -InstallDir "$pwd/.dotnetcli" -NoPath -Version $RequiredDotnetVersion
if ($LASTEXITCODE) { exit 1 }

$env:Path = "$pwd/.dotnetcli;$env:Path"
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '{build}'
skip_tags: true
image: Visual Studio 2017
install:
- ps: mkdir -Force ".\build\" | Out-Null
- ps: ./Setup.ps1
build_script:
- ps: ./Build.ps1
test: off
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.2.105"
"version": "3.0.100"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.AspNetCore\Serilog.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>

</Project>
21 changes: 10 additions & 11 deletions samples/EarlyInitializationSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.IO;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace EarlyInitializationSample
Expand All @@ -23,16 +23,14 @@ public static int Main(string[] args)
.Enrich.FromLogContext()
.WriteTo.Debug()
.WriteTo.Console(
// {Properties:j} added:
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} " +
"{Properties:j}{NewLine}{Exception}")
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}")
.CreateLogger();

try
{
Log.Information("Getting the motors running...");

BuildWebHost(args).Run();
CreateHostBuilder(args).Build().Run();

return 0;
}
Expand All @@ -47,11 +45,12 @@ public static int Main(string[] args)
}
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseConfiguration(Configuration)
.UseSerilog()
.Build();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseSerilog();
}
}
37 changes: 10 additions & 27 deletions samples/EarlyInitializationSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,19 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace EarlyInitializationSample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});


services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
Expand All @@ -41,21 +22,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseStaticFiles();

// Write streamlined request completion events, instead of the more verbose ones from the framework.
// To use the default framework request logging instead, remove this line and set the "Microsoft"
// level in appsettings.json to "Information".
app.UseSerilogRequestLogging();

app.UseStaticFiles();
app.UseCookiePolicy();
app.UseRouting();

app.UseMvc(routes =>
app.UseEndpoints(endpoints =>
{
routes.MapRoute(
endpoints.MapControllerRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Serilog.AspNetCore\Serilog.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>

</Project>
19 changes: 10 additions & 9 deletions samples/InlineInitializationSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace InlineInitializationSample
Expand All @@ -8,19 +8,20 @@ public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
CreateHostBuilder(args).Build().Run();
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.FromLogContext()
.WriteTo.Debug()
.WriteTo.Console(
// {Properties:j} added:
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} " +
"{Properties:j}{NewLine}{Exception}"));
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} {Properties:j}{NewLine}{Exception}"));
}
}
41 changes: 13 additions & 28 deletions samples/InlineInitializationSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
using Microsoft.AspNetCore.Builder;
using System.Net;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;

namespace InlineInitializationSample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});


services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
Expand All @@ -41,21 +24,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseStaticFiles();

// Write streamlined request completion events, instead of the more verbose ones from the framework.
// To use the default framework request logging instead, remove this line and set the "Microsoft"
// level in appsettings.json to "Information".
app.UseSerilogRequestLogging();

app.UseStaticFiles();
app.UseCookiePolicy();
app.UseRouting();

app.UseMvc(routes =>
app.UseEndpoints(endpoints =>
{
routes.MapRoute(
endpoints.MapControllerRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions serilog-aspnetcore.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
# Visual Studio Version 16
VisualStudioVersion = 16.0.29209.62
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0}"
EndProject
Expand All @@ -16,6 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9
global.json = global.json
README.md = README.md
assets\Serilog.snk = assets\Serilog.snk
Setup.ps1 = Setup.ps1
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.AspNetCore", "src\Serilog.AspNetCore\Serilog.AspNetCore.csproj", "{0549D23F-986B-4FB2-BACE-16FD7A7BC9EF}"
Expand Down
Loading