依赖项——右键——管理NuGet程序包——浏览——输入以下内容

Install-Package NLog.Extensions.Logging -Pre

在根目录下添加nlog.config

  更改nlog.config中内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<targets>
<target name="logfile" xsi:type="File" fileName="logs/${shortdate}.log" />
</targets> <rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>


选择项目——右键——在文件资源管理器中打开文件夹打开——打开WebApi_Core.csproj——添加以下内容:
<ItemGroup>
<Content Update="nlog.config" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>


双击Startup.cs——更改Configure中内容:
ILoggerFactory loggerFactory
loggerFactory.AddNLog();

在Controller中添加以下内容测试:


运行这个方法

选择项目——右键——在文件资源管理器中打开文件夹打开——打开bin—Debug—netcoreapp2.0—logs:

单独配置

最新文章

  1. js阿拉伯数字转中文大写
  2. Android数据库 — — —查询数据
  3. Microsoft Dynamics CRM 2013 安装程序及SDK 下载地址
  4. 学习web前端三个月感悟
  5. (五)ASP.NET中动态生成控件
  6. Spring Named Parameters examples in SimpleJdbcTemplate
  7. [译]GotW #3: Using the Standard Library (or, Temporaries Revisited)
  8. [Tree]Count Complete Tree Nodes
  9. LaTeX中titlesec宏包的使用
  10. Maven Jrebel 多模块热部署方案
  11. 面试经典-设计包含min函数的栈
  12. IP地址与域名的关系
  13. mysql 批量导入
  14. Problem B: 一切皆对象
  15. TypeScript: this bind 和 回调的正确用法
  16. 转 Java操作PDF之iText详细入门
  17. Codeforces519 E. A and B and Lecture Rooms
  18. PHP操作MongoDB 数据库
  19. phpstudy----------phpstudy开启apache日志并且按照日期划分创建。
  20. 修改JAVA代码,需要重启Tomcat的原因

热门文章

  1. 02 IDEA创创建第一个maven工程
  2. Docker Swarm学习教程【转载】
  3. form submission
  4. [WCF REST] WebServiceHost 不依赖配置文件启动简单服务
  5. 杂项-Unicode:Unicode
  6. PHP获得计算机的唯一标识[cpu,网卡]
  7. vue封装分页组件
  8. LeetCode 114. Flatten Binary Tree to Linked List 动态演示
  9. Recurrent Neural Network(1):Architecture
  10. 编程语言 - 脚本编程 - JavaScript/Jquery/Ajax/XML/JSON/ActionScript3