.net core 添加NLog
2024-09-06 01:42:34
依赖项——右键——管理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:
单独配置
最新文章
- js阿拉伯数字转中文大写
- Android数据库 — — —查询数据
- Microsoft Dynamics CRM 2013 安装程序及SDK 下载地址
- 学习web前端三个月感悟
- (五)ASP.NET中动态生成控件
- Spring Named Parameters examples in SimpleJdbcTemplate
- [译]GotW #3: Using the Standard Library (or, Temporaries Revisited)
- [Tree]Count Complete Tree Nodes
- LaTeX中titlesec宏包的使用
- Maven Jrebel 多模块热部署方案
- 面试经典-设计包含min函数的栈
- IP地址与域名的关系
- mysql 批量导入
- Problem B: 一切皆对象
- TypeScript: this bind 和 回调的正确用法
- 转 Java操作PDF之iText详细入门
- Codeforces519 E. A and B and Lecture Rooms
- PHP操作MongoDB 数据库
- phpstudy----------phpstudy开启apache日志并且按照日期划分创建。
- 修改JAVA代码,需要重启Tomcat的原因
热门文章
- 02 IDEA创创建第一个maven工程
- Docker Swarm学习教程【转载】
- form submission
- [WCF REST] WebServiceHost 不依赖配置文件启动简单服务
- 杂项-Unicode:Unicode
- PHP获得计算机的唯一标识[cpu,网卡]
- vue封装分页组件
- LeetCode 114. Flatten Binary Tree to Linked List 动态演示
- Recurrent Neural Network(1):Architecture
- 编程语言 - 脚本编程 - JavaScript/Jquery/Ajax/XML/JSON/ActionScript3