Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,5 @@ project.lock.json

# JetBrains Rider
.idea

.vscode
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
dotnet --info
dotnet restore

for path in src/**/*.csproj; do
dotnet build -f netstandard1.3 -c Release ${path}
dotnet build -f netstandard2.0 -c Release ${path}

done

for path in test/*.Tests/*.csproj; do
dotnet test -f netcoreapp2.0 -c Release ${path}
done
40 changes: 40 additions & 0 deletions samples/SimpleWebAPISample/Controllers/ScopesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Serilog;
using Microsoft.Extensions.Logging;

namespace SimpleWebAPISample.Controllers
{
[Route("api/[controller]")]
public class ScopesController : Controller
{
ILogger<ScopesController> _logger;

public ScopesController(ILogger<ScopesController> logger)
{
_logger = logger;
}

// GET api/scopes
[HttpGet]
public IEnumerable<string> Get()
{
_logger.LogInformation("Before");

using (_logger.BeginScope("Some name"))
using (_logger.BeginScope(42))
using (_logger.BeginScope("Formatted {WithValue}", 12345))
using (_logger.BeginScope(new Dictionary<string, object> { ["ViaDictionary"] = 100 }))
{
_logger.LogInformation("Hello from the Index!");
}

_logger.LogInformation("After");

return new string[] { "value1", "value2" };
}
}
}
22 changes: 22 additions & 0 deletions samples/SimpleWebAPISample/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace SimpleWebAPISample.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
// Directly through Serilog
Log.Information("This is a handler for {Path}", Request.Path);
return new string[] { "value1", "value2" };
}
}
}
39 changes: 39 additions & 0 deletions samples/SimpleWebAPISample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

using Serilog;

namespace SimpleWebAPISample
{
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.LiterateConsole()
.CreateLogger();

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

BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(log =>
{
log.SetMinimumLevel(LogLevel.Information);
log.AddSerilog(logger: Log.Logger, dispose: true);
})
.Build();
}
}
20 changes: 20 additions & 0 deletions samples/SimpleWebAPISample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This is a simple example illustrating the use of Serilog with WebAPI.

The project was created with the following steps.

* Create the project and add NuGet dependencies
```
dotnet new webapi
dotnet add package Serilog.Extensions.Logging
dotnet add package Serilog.Sinks.Literate
```

* Extend the logging to include Serilog. See `Program.cs`
```
.ConfigureLogging(log =>
{
log.AddSerilog(logger: Log.Logger, dispose: true);
})
```

* Logging can then used directly to Serilog or via the `Microsoft.Extensions.Logging` pipeline.
16 changes: 16 additions & 0 deletions samples/SimpleWebAPISample/SimpleWebAPISample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
40 changes: 40 additions & 0 deletions samples/SimpleWebAPISample/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace SimpleWebAPISample
{
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.AddMvc();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
}
}
}
10 changes: 10 additions & 0 deletions samples/SimpleWebAPISample/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
15 changes: 15 additions & 0 deletions samples/SimpleWebAPISample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}
39 changes: 39 additions & 0 deletions samples/SimpleWebSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

using Serilog;

namespace SimpleWebSample
{
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.LiterateConsole()
.CreateLogger();

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

BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.ConfigureLogging(log =>
{
log.SetMinimumLevel(LogLevel.Information);
log.AddSerilog(logger: Log.Logger, dispose: true);
})
.Build();
}
}
20 changes: 20 additions & 0 deletions samples/SimpleWebSample/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
This is a simple example illustrating the use of Serilog with a web app.

The project was created with the following steps.

* Create the project and add NuGet dependencies
```
dotnet new web
dotnet add package Serilog.Extensions.Logging
dotnet add package Serilog.Sinks.Literate
```

* Extend the logging to include Serilog. See `Program.cs`
```
.ConfigureLogging(log =>
{
log.AddSerilog(logger: Log.Logger, dispose: true);
})
```

* Logging can then used directly to Serilog or via the `Microsoft.Extensions.Logging` pipeline.
13 changes: 13 additions & 0 deletions samples/SimpleWebSample/SimpleWebSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.0" />
</ItemGroup>
</Project>
34 changes: 34 additions & 0 deletions samples/SimpleWebSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;

namespace SimpleWebSample
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
}
3 changes: 0 additions & 3 deletions samples/WebSample/.bowerrc

This file was deleted.

Loading