【问题标题】:Visual Studio: Archive the contents of a text file once a monthVisual Studio:每月归档一次文本文件的内容
【发布时间】:2014-05-15 00:20:32
【问题描述】:

使用 Visual Studio 2013 ASP .NET MVC 5,我有这个 .txt 文件,我在其中记录了在我的 Web 应用程序中捕获的异常(使用 NLog)。每个月,我都想将该文件归档到我项目中的不同文件夹中。我怎样才能做到这一点?谢谢

【问题讨论】:

  • 您是否碰巧遵循任何特定文档,或者您只是使用“常识”?意思是,您知道如何开发 .net mvc 应用程序并且只是遵循 nlog 文档?另外,您对 nlog 和 mvc5 的组合满意吗?

标签: visual-studio asp.net-mvc-5 nlog error-logging archiving


【解决方案1】:

我认为可以这样做

<?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" internalLogFile="c:/logs/nlog_ex.txt" internalLogLevel="Debug">

  <!-- 
  See http://nlog-project.org/wiki/Configuration_file 
  for information on customizing logging rules and outputs.
   -->
  <targets>
    <target xsi:type="File"
            name="exceptions"
            encoding="utf-8"
            lineEnding="Default"
            layout="${longdate} - ${message}"
            archiveFileName="c:/logs/${date:format=yyyy-MM}/exceptions.txt"
            archiveNumbering="Sequence"
            archiveEvery="Month"
            fileName="c:/logs/exceptions.txt"
            deleteOldFileOnStartup="false"
            enableFileDelete="true"
            createDirs="true"
            concurrentWrites="true"
            autoFlush="true"
            keepFileOpen="false"
    />
  </targets>

  <rules>
    <!-- add your logging rules here -->
    <logger name="*" minlevel="Info" writeTo="exceptions" />
  </rules>
</nlog>

我用过这个domcumentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多