From dba2767a19796d5e6f6e3d43ee1c17e91c9545b5 Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Sat, 26 Oct 2019 03:14:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ValuesController.cs | 58 +++++++++++++++++++ LogStudy.WebApp/LogStudy.WebApp.csproj | 19 ++++++ LogStudy.WebApp/Program.cs | 36 ++++++++++++ .../Properties/launchSettings.json | 30 ++++++++++ LogStudy.WebApp/Startup.cs | 41 +++++++++++++ LogStudy.WebApp/appsettings.Development.json | 9 +++ LogStudy.WebApp/appsettings.json | 8 +++ LogStudy.sln | 25 ++++++++ 8 files changed, 226 insertions(+) create mode 100644 LogStudy.WebApp/Controllers/ValuesController.cs create mode 100644 LogStudy.WebApp/LogStudy.WebApp.csproj create mode 100644 LogStudy.WebApp/Program.cs create mode 100644 LogStudy.WebApp/Properties/launchSettings.json create mode 100644 LogStudy.WebApp/Startup.cs create mode 100644 LogStudy.WebApp/appsettings.Development.json create mode 100644 LogStudy.WebApp/appsettings.json create mode 100644 LogStudy.sln diff --git a/LogStudy.WebApp/Controllers/ValuesController.cs b/LogStudy.WebApp/Controllers/ValuesController.cs new file mode 100644 index 0000000..b54bca1 --- /dev/null +++ b/LogStudy.WebApp/Controllers/ValuesController.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace LogStudy.WebApp.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + private ILogger _logger; + public ValuesController(ILogger logger) + { + _logger = logger; + } + + // GET api/values + [HttpGet] + public ActionResult> Get() + { + _logger.LogCritical("我是测试"); + + _logger.LogDebug("我是Debug测试"); + + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/LogStudy.WebApp/LogStudy.WebApp.csproj b/LogStudy.WebApp/LogStudy.WebApp.csproj new file mode 100644 index 0000000..fe62861 --- /dev/null +++ b/LogStudy.WebApp/LogStudy.WebApp.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.2 + InProcess + + + + + + + + + + + + + + diff --git a/LogStudy.WebApp/Program.cs b/LogStudy.WebApp/Program.cs new file mode 100644 index 0000000..876bec1 --- /dev/null +++ b/LogStudy.WebApp/Program.cs @@ -0,0 +1,36 @@ +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; + +namespace LogStudy.WebApp +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .ConfigureLogging((hostbuildContext, logBuild) => { + var config = hostbuildContext.Configuration; + var ev = hostbuildContext.HostingEnvironment; + + logBuild + .AddConsole() + .AddDebug() + .AddEventLog() + .AddEventSourceLogger() + .AddTraceSource("NetCoreDemo") + .SetMinimumLevel(LogLevel.Information); + }) + .UseStartup(); + } +} diff --git a/LogStudy.WebApp/Properties/launchSettings.json b/LogStudy.WebApp/Properties/launchSettings.json new file mode 100644 index 0000000..53a8c1d --- /dev/null +++ b/LogStudy.WebApp/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:51764", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "LogStudy.WebApp": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/LogStudy.WebApp/Startup.cs b/LogStudy.WebApp/Startup.cs new file mode 100644 index 0000000..c8845ee --- /dev/null +++ b/LogStudy.WebApp/Startup.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace LogStudy.WebApp +{ + 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().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + } + + // 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(); + } + } +} diff --git a/LogStudy.WebApp/appsettings.Development.json b/LogStudy.WebApp/appsettings.Development.json new file mode 100644 index 0000000..e203e94 --- /dev/null +++ b/LogStudy.WebApp/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/LogStudy.WebApp/appsettings.json b/LogStudy.WebApp/appsettings.json new file mode 100644 index 0000000..def9159 --- /dev/null +++ b/LogStudy.WebApp/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/LogStudy.sln b/LogStudy.sln new file mode 100644 index 0000000..7ec4c3d --- /dev/null +++ b/LogStudy.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29418.71 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogStudy.WebApp", "LogStudy.WebApp\LogStudy.WebApp.csproj", "{8516CD13-0513-46AF-897F-05FCD66933A2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8516CD13-0513-46AF-897F-05FCD66933A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8516CD13-0513-46AF-897F-05FCD66933A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8516CD13-0513-46AF-897F-05FCD66933A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8516CD13-0513-46AF-897F-05FCD66933A2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4D9A3A36-98D0-498C-B78A-2E5CFC5195AC} + EndGlobalSection +EndGlobal