# net.core-WebApiFrame **Repository Path**: LIAOKUI/net.core-WebApiFrame ## Basic Information - **Project Name**: net.core-WebApiFrame - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-02-10 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 下载vscode https://code.visualstudio.com/ 安装完成 如果想用中文版 打开vscode shift+ctrl+p 输入 configure disply language "locale":"en" 修改为 zh-CN 重启如果还不是中文,需要安装插件 扩展 搜索 Chinese (Simplified) Language Pack 安装在重启就好了, 下载vscode sdk https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-2.2.103-windows-x64-installer 推荐使用最新版本 创建一个netcore 应用程序 新建目录 G:/NetcoreWork 打开cmd 执行下面命令 PS C:\Windows\system32> CD G:/NetcoreWork md WebApiFrom cd WebApiFrom dotnet new webapi dotnet run 使用vscode 打开项目 cd 执行 dotnet restore 更新nuget package f5调试项目 正常运行 //添加nlog nuget 添加NLog和 NLog.Extensions.Logging Startup 添加 public void Configure(IApplicationBuilder app, IHostingEnvironment env , ILoggerFactory loggerFactory ) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } //添加日志支持 NLog.LogManager.LoadConfiguration("config/nlog.config").GetCurrentClassLogger(); app.UseHttpsRedirection(); app.UseMvc(); } 添加配置文件 nlog.config 日志输出到 log文件夹下 添加测试 [Route("api/[controller]")] [ApiController] public class TestController:ControllerBase { private ILogger _logger; public TestController(ILogger logger) { _logger=logger; } [HttpGet] public ActionResult Get() { _logger.LogInformation("This is Information Log!"); _logger.LogWarning("This is Warning Log!"); _logger.LogError("This is Error Log!"); return "result"; } } 执行项目正常输入日志信息