小编And*_*rey的帖子

为什么我不能使用 nlog 将跟踪记录写入文件?

我开始学习如何在 .net core web API 应用程序中配置 nlog。并阅读了一些教程,并尝试从github的官方教程中实现实现

1)创建nlog.confiqxml文件

<?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" 
  autoReload="true" 
  internalLogLevel="Trace" 
  internalLogFile="D:/Projects/appstore2/AppStore/AppStore.DataAccessLayer/Logs/InnerLog.txt">

<extensions>
  <!--enable NLog.Web for ASP.NET Core-->
  <add assembly="NLog.Web.AspNetCore"/>
</extensions>

<variable name="PathToFile" value="D:/Projects/appstore2/AppStore/AppStore.DataAccessLayer/Logs"/>

<!-- define various log targets -->
<targets async="true">    
  <!-- write logs to file -->
  <target name="logfile" xsi:type="File" fileName="D:/Projects/appstore2/AppStore/AppStore.DataAccessLayer/Logs/${shortdate}_log.txt" layout="${longdate} ${level:uppercase=true} ${message}"/>

</targets>

<rules>
  <logger name="*" minlevel="Trace" writeTo="logfile" final="true"/>
</rules>
Run Code Online (Sandbox Code Playgroud)

2)配置我的Programm.cs

public class Program
{
    public static void Main(string[] args)
    {
        var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

        try
        {
            logger.Debug("init main"); …
Run Code Online (Sandbox Code Playgroud)

c# logging nlog asp.net-web-api asp.net-core

1
推荐指数
1
解决办法
1789
查看次数

标签 统计

asp.net-core ×1

asp.net-web-api ×1

c# ×1

logging ×1

nlog ×1