Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
51 changes: 31 additions & 20 deletions samples/SimpleWebAPISample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
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)
public static int Main(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One slight annoyance here - any idea how to get the information about the hosting environment - Development, Production etc. - without resolving IHostingEnvironment from DI?

.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 = WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseConfiguration(configuration)
.UseSerilog()
.Build();

host.Run();

return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Unhandled exception");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
}
}
27 changes: 27 additions & 0 deletions samples/SimpleWebAPISample/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:51968/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SimpleWebAPISample": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:51972/"
}
}
}
4 changes: 2 additions & 2 deletions samples/SimpleWebAPISample/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 webapi
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.
15 changes: 12 additions & 3 deletions samples/SimpleWebAPISample/SimpleWebAPISample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@
<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>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>

</Project>
16 changes: 6 additions & 10 deletions samples/SimpleWebAPISample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Information",
"System": "Warning"
}
}
}
Expand Down
52 changes: 31 additions & 21 deletions samples/SimpleWebSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
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)
.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 = WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseConfiguration(configuration)
.UseSerilog()
.Build();

host.Run();

return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Unhandled exception");
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>
10 changes: 10 additions & 0 deletions samples/SimpleWebSample/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"
}
}
}
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"
}
}
}
}
32 changes: 21 additions & 11 deletions serilog-extensions-logging.sln
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26114.2
VisualStudioVersion = 15.0.26730.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Extensions.Logging", "src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Extensions.Logging", "src\Serilog.Extensions.Logging\Serilog.Extensions.Logging.csproj", "{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog.Extensions.Logging.Tests", "test\Serilog.Extensions.Logging.Tests\Serilog.Extensions.Logging.Tests.csproj", "{37EADF84-5E41-4224-A194-1E3299DCD0B8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Extensions.Logging.Tests", "test\Serilog.Extensions.Logging.Tests\Serilog.Extensions.Logging.Tests.csproj", "{37EADF84-5E41-4224-A194-1E3299DCD0B8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F2407211-6043-439C-8E06-3641634332E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "samples\Sample\Sample.csproj", "{65357FBC-9BC4-466D-B621-1C3A19BC2A78}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "samples\Sample\Sample.csproj", "{65357FBC-9BC4-466D-B621-1C3A19BC2A78}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{9C21B9DF-AEDD-4AA6-BEA4-912DEF3E5B8E}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
Build.ps1 = Build.ps1
global.json = global.json
README.md = README.md
assets\Serilog.snk = assets\Serilog.snk
global.json = global.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSample", "samples\WebSample\WebSample.csproj", "{486DF7EB-128D-4C79-8B97-9CEFEADDB948}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleWebSample", "samples\SimpleWebSample\SimpleWebSample.csproj", "{69F9A0ED-7910-4F33-8919-28BB05376FBC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleWebAPISample", "samples\SimpleWebAPISample\SimpleWebAPISample.csproj", "{010CECCE-2E92-4C3F-BED9-9AD572E170C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -44,10 +46,14 @@ Global
{65357FBC-9BC4-466D-B621-1C3A19BC2A78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65357FBC-9BC4-466D-B621-1C3A19BC2A78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65357FBC-9BC4-466D-B621-1C3A19BC2A78}.Release|Any CPU.Build.0 = Release|Any CPU
{486DF7EB-128D-4C79-8B97-9CEFEADDB948}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{486DF7EB-128D-4C79-8B97-9CEFEADDB948}.Debug|Any CPU.Build.0 = Debug|Any CPU
{486DF7EB-128D-4C79-8B97-9CEFEADDB948}.Release|Any CPU.ActiveCfg = Release|Any CPU
{486DF7EB-128D-4C79-8B97-9CEFEADDB948}.Release|Any CPU.Build.0 = Release|Any CPU
{69F9A0ED-7910-4F33-8919-28BB05376FBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69F9A0ED-7910-4F33-8919-28BB05376FBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69F9A0ED-7910-4F33-8919-28BB05376FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69F9A0ED-7910-4F33-8919-28BB05376FBC}.Release|Any CPU.Build.0 = Release|Any CPU
{010CECCE-2E92-4C3F-BED9-9AD572E170C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{010CECCE-2E92-4C3F-BED9-9AD572E170C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{010CECCE-2E92-4C3F-BED9-9AD572E170C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{010CECCE-2E92-4C3F-BED9-9AD572E170C5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -56,6 +62,10 @@ Global
{903CD13A-D54B-4CEC-A55F-E22AE3D93B3B} = {A1893BD1-333D-4DFE-A0F0-DDBB2FE526E0}
{37EADF84-5E41-4224-A194-1E3299DCD0B8} = {E30F638E-BBBE-4AD1-93CE-48CC69CFEFE1}
{65357FBC-9BC4-466D-B621-1C3A19BC2A78} = {F2407211-6043-439C-8E06-3641634332E7}
{486DF7EB-128D-4C79-8B97-9CEFEADDB948} = {F2407211-6043-439C-8E06-3641634332E7}
{69F9A0ED-7910-4F33-8919-28BB05376FBC} = {F2407211-6043-439C-8E06-3641634332E7}
{010CECCE-2E92-4C3F-BED9-9AD572E170C5} = {F2407211-6043-439C-8E06-3641634332E7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {811E61C5-3871-4633-AFAE-B35B619C8A10}
EndGlobalSection
EndGlobal
Loading