概述
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:
转载于:https://www.cnblogs.com/summert/p/9083370.html
最后
以上就是笨笨夏天为你收集整理的.Net Core WebApi(二)——添加Nlog的全部内容,希望文章能够帮你解决.Net Core WebApi(二)——添加Nlog所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复