Skip to content

Commit 49b328b

Browse files
committed
Added simple web example.
* Vanilla web app without mvc/razor
1 parent 2e5b759 commit 49b328b

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,5 @@ project.lock.json
199199

200200
# JetBrains Rider
201201
.idea
202+
203+
.vscode

samples/SimpleWebSample/Program.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
using Serilog;
12+
13+
namespace SimpleWebSample
14+
{
15+
public class Program
16+
{
17+
public static void Main(string[] args)
18+
{
19+
Log.Logger = new LoggerConfiguration()
20+
.Enrich.FromLogContext()
21+
.WriteTo.LiterateConsole()
22+
.CreateLogger();
23+
24+
Log.Information("Getting the motors running...");
25+
26+
BuildWebHost(args).Run();
27+
}
28+
29+
public static IWebHost BuildWebHost(string[] args) =>
30+
WebHost.CreateDefaultBuilder(args)
31+
.UseStartup<Startup>()
32+
.ConfigureLogging(log =>
33+
{
34+
log.SetMinimumLevel(LogLevel.Information);
35+
log.AddSerilog(logger: Log.Logger, dispose: true);
36+
})
37+
.Build();
38+
}
39+
}

samples/SimpleWebSample/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
```
2+
dotnet new web
3+
dotnet add package Serilog.Extensions.Logging
4+
dotnet add package Serilog.Sinks.Literate
5+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Folder Include="wwwroot\" />
7+
</ItemGroup>
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
10+
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.0" />
11+
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.0" />
12+
</ItemGroup>
13+
</Project>

samples/SimpleWebSample/Startup.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.AspNetCore.Http;
8+
using Microsoft.Extensions.DependencyInjection;
9+
10+
namespace SimpleWebSample
11+
{
12+
public class Startup
13+
{
14+
// This method gets called by the runtime. Use this method to add services to the container.
15+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
16+
public void ConfigureServices(IServiceCollection services)
17+
{
18+
}
19+
20+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
21+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
22+
{
23+
if (env.IsDevelopment())
24+
{
25+
app.UseDeveloperExceptionPage();
26+
}
27+
28+
app.Run(async (context) =>
29+
{
30+
await context.Response.WriteAsync("Hello World!");
31+
});
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)