Skip to content

Commit

Permalink
Logging in .net core middleware test
Browse files Browse the repository at this point in the history
  • Loading branch information
oazabir committed Jul 5, 2016
1 parent f13ae00 commit ca37356
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions DotNetCore/HackerSpray.Middleware.Test/TestMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
using Microsoft.AspNetCore.Http.Features;
using HackerSpray.Module;
using System.Threading;
using Serilog;
using System.IO;
using Serilog.Sinks.RollingFile;

namespace HackerSpray.Middleware.Test
{
Expand Down Expand Up @@ -46,12 +49,20 @@ private TestServer GetServer()

builder.AddEnvironmentVariables();
var config = builder.Build();

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.Enrich.FromLogContext()
.WriteTo.RollingFile("C:\\inetpub\\logs\\LogFiles\\log-{Date}.txt")
.CreateLogger();

var bldr = new WebHostBuilder()
.Configure(app =>
{
var loggerFactory = app.ApplicationServices.GetService<ILoggerFactory>();
loggerFactory.AddConsole(config.GetSection("Logging"));
loggerFactory.AddDebug(LogLevel.Debug);
loggerFactory.AddSerilog();

app.UseXForwardedFor();
app.UseHackerSpray();
Expand Down
6 changes: 5 additions & 1 deletion DotNetCore/HackerSpray.Middleware.Test/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-final",
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Hosting": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-final"
"Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-final",
"System.Diagnostics.TextWriterTraceListener": "4.0.0-beta-23516",
"Serilog": "2.0.0-rc-622",
"Serilog.Sinks.Seq": "2.0.0-rc-55",
"Serilog.Extensions.Logging": "1.0.0-rc2-10110"
},

"frameworks": {
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ The log shows you how long ``Hacker.Defend`` function is taking to execute, whic

## Measuring performance impact

In .NET 4 version, look for this in the log:

```
[Verbose] Defend: 1
```

This records how many milliseconds it has taken to perform the ``Defend`` operation.

.NET core logs in this format:

Expand Down

0 comments on commit ca37356

Please sign in to comment.