Skip to content

Commit

Permalink
Add sample
Browse files Browse the repository at this point in the history
  • Loading branch information
xsoheilalizadeh committed Jan 17, 2020
1 parent a33194e commit fab7a7f
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 0 deletions.
9 changes: 9 additions & 0 deletions raccoonLog.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{8C9919E9-D
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "raccoonLog.Tests", "test\raccoonLog.Tests\raccoonLog.Tests.csproj", "{906D071A-5900-4DE5-A55A-21C635D6D4F0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{C5D71756-E0E5-4C0B-A22B-3DCC1C46C151}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpLoggingSample", "sample\HttpLoggingSample\HttpLoggingSample.csproj", "{37742C8A-64C2-4CF0-BCC3-653E0E4F8025}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,6 +43,10 @@ Global
{906D071A-5900-4DE5-A55A-21C635D6D4F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{906D071A-5900-4DE5-A55A-21C635D6D4F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{906D071A-5900-4DE5-A55A-21C635D6D4F0}.Release|Any CPU.Build.0 = Release|Any CPU
{37742C8A-64C2-4CF0-BCC3-653E0E4F8025}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37742C8A-64C2-4CF0-BCC3-653E0E4F8025}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37742C8A-64C2-4CF0-BCC3-653E0E4F8025}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37742C8A-64C2-4CF0-BCC3-653E0E4F8025}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -47,6 +55,7 @@ Global
{55F9CF01-6956-40A0-8BB3-2F4DE095F314} = {88F9305A-56B3-4F40-B57D-051659963650}
{61FD4468-E019-43F5-BF7C-653C964D8164} = {88F9305A-56B3-4F40-B57D-051659963650}
{906D071A-5900-4DE5-A55A-21C635D6D4F0} = {8C9919E9-D1EB-483C-92DF-299F3279CA5B}
{37742C8A-64C2-4CF0-BCC3-653E0E4F8025} = {C5D71756-E0E5-4C0B-A22B-3DCC1C46C151}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DD751939-CA3E-406E-BFE0-20C0E1CD5770}
Expand Down
39 changes: 39 additions & 0 deletions sample/HttpLoggingSample/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;

namespace HttpLoggingSample.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

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

[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}
12 changes: 12 additions & 0 deletions sample/HttpLoggingSample/HttpLoggingSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\raccoonLog.Http\raccoonLog.Http.csproj" />
</ItemGroup>


</Project>
26 changes: 26 additions & 0 deletions sample/HttpLoggingSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace HttpLoggingSample
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
30 changes: 30 additions & 0 deletions sample/HttpLoggingSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:53221",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"HttpLoggingSample": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
56 changes: 56 additions & 0 deletions sample/HttpLoggingSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using raccoonLog;
using raccoonLog.Http;
using raccoonLog.Http.Stores;

namespace HttpLoggingSample
{
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.AddControllers();

services.AddRaccoonLog(builder =>
{
builder.AddHttpLogging()
.AddFileStore();
});
}

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

app.UseRouting();

app.UseAuthorization();

app.UseRaccoonLog(builder =>
{
builder.EnableHttpLogging();
});

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
15 changes: 15 additions & 0 deletions sample/HttpLoggingSample/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace HttpLoggingSample
{
public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
}
9 changes: 9 additions & 0 deletions sample/HttpLoggingSample/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions sample/HttpLoggingSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

0 comments on commit fab7a7f

Please sign in to comment.