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
39 changes: 0 additions & 39 deletions samples/SimpleWebAPISample/Program.cs

This file was deleted.

20 changes: 0 additions & 20 deletions samples/SimpleWebAPISample/README.md

This file was deleted.

16 changes: 0 additions & 16 deletions samples/SimpleWebAPISample/SimpleWebAPISample.csproj

This file was deleted.

40 changes: 0 additions & 40 deletions samples/SimpleWebAPISample/Startup.cs

This file was deleted.

15 changes: 0 additions & 15 deletions samples/SimpleWebAPISample/appsettings.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
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
namespace SimpleWebSample.Controllers
{
[Route("api/[controller]")]
public class ScopesController : Controller
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Serilog;

namespace SimpleWebAPISample.Controllers
namespace SimpleWebSample.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
Expand Down
56 changes: 35 additions & 21 deletions samples/SimpleWebSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,53 @@
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)
public static int Main(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true)
.Build();

Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.Enrich.FromLogContext()
.WriteTo.LiterateConsole()
.WriteTo.Console()
.CreateLogger();

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

BuildWebHost(args).Run();
}
try
{
Log.Information("Getting the motors running...");

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();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseConfiguration(configuration)
.UseSerilog()
.Build();

host.Run();

return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
}
}
27 changes: 27 additions & 0 deletions samples/SimpleWebSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:51965/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SimpleWebSample": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:51966/"
}
}
}
4 changes: 2 additions & 2 deletions samples/SimpleWebSample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The project was created with the following steps.
```
dotnet new web
dotnet add package Serilog.Extensions.Logging
dotnet add package Serilog.Sinks.Literate
dotnet add package Serilog.Sinks.Console
```

* Extend the logging to include Serilog. See `Program.cs`
Expand All @@ -17,4 +17,4 @@ dotnet add package Serilog.Sinks.Literate
})
```

* Logging can then used directly to Serilog or via the `Microsoft.Extensions.Logging` pipeline.
* Logging can then used directly to Serilog or via the `Microsoft.Extensions.Logging` pipeline.
13 changes: 11 additions & 2 deletions samples/SimpleWebSample/SimpleWebSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

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

<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" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.0.1" />
<PackageReference Include="Serilog" Version="2.5.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="2.4.0" />

</ItemGroup>

</Project>
18 changes: 12 additions & 6 deletions samples/SimpleWebSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace SimpleWebSample
{
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.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand All @@ -25,6 +29,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseDeveloperExceptionPage();
}

app.UseMvc();

app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
Expand Down
11 changes: 11 additions & 0 deletions samples/SimpleWebSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
}
}
Loading