在Linux上运行的dotnet核心nlog只记录一个条目

时间:2016-09-09 06:47:23

标签: linux asp.net-core nlog .net-core kestrel-http-server

我使用Kestrel在Linux上运行aspnet核心站点。我已经设置了nlog来登录csv文件。一切都在我的Windows开发环境中很好,但是当我在Linux上运行时,我只在日志文件中获得一个条目。我打开了nlog跟踪,在输出中发现了以下错误:

2016-09-09 07:22:46.2123 Error Error has been raised. Exception: System.IO.IOException: The file '/var/aspnetcore/CSWebSite/releases/20160909061254/logs/archives/own-log.20160908.csv' already exists.
   at System.IO.UnixFileSystem.MoveFile(String sourceFullPath, String destFullPath)
   at System.IO.File.Move(String sourceFileName, String destFileName)
   at NLog.Targets.FileTarget.ArchiveByDate(String fileName, String pattern, LogEventInfo logEvent)
   at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
   at NLog.Targets.FileTarget.FlushCurrentFileWrites(String currentFileName, LogEventInfo firstLogEvent, MemoryStream ms, List`1 pendingContinuations)
2016-09-09 07:22:46.2123 Error Error has been raised. Exception: System.IO.IOException: The file '/var/aspnetcore/CSWebSite/releases/20160909061254/logs/archives/all-log.20160907.csv' already exists.
   at System.IO.UnixFileSystem.MoveFile(String sourceFullPath, String destFullPath)
   at System.IO.File.Move(String sourceFileName, String destFileName)
   at NLog.Targets.FileTarget.ArchiveByDate(String fileName, String pattern, LogEventInfo logEvent)
   at NLog.Targets.FileTarget.ProcessLogEvent(LogEventInfo logEvent, String fileName, Byte[] bytesToWrite)
   at NLog.Targets.FileTarget.FlushCurrentFileWrites(String currentFileName, LogEventInfo firstLogEvent, MemoryStream ms, List`1 pendingContinuations)

这是我的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">
    <extensions>
        <!--enable NLog.Web for ASP.NET Core-->
        <add assembly="NLog.Web.AspNetCore"/>
    </extensions>
    <targets>
        <!-- https://github.com/nlog/nlog/wiki/File-target -->
        <!-- http://stackoverflow.com/questions/34679727/use-nlog-in-asp-net-5-application -->
        <target name="allfile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
            <target name="allfile" xsi:type="File"
                    fileName="${basedir}/logs/all-logfile.csv"
                    archiveFileName="${basedir}/logs/archives/all-log.{#}.csv"
                    archiveEvery="Day"
                    archiveNumbering="Date"
                    archiveDateFormat="yyyyMMdd"
                    maxArchiveFiles="28"
                    concurrentWrites="true"
                    keepFileOpen="false"
                    encoding="utf-8">
                <layout xsi:type="CSVLayout">
                    <column name="time" layout="${longdate}" />
                    <column name="logger" layout="${logger}" />
                    <column name="authtype" layout="${aspnet-user-authtype}" />
                    <column name="identity" layout="${aspnet-user-identity}" />
                    <column name="level" layout="${uppercase:${level}}" />
                    <column name="message" layout="${message} ${exception:format=ToString,StackTrace}" />
                </layout>
            </target>
        </target>
        <target name="ownfile" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
            <target name="ownfile" xsi:type="File"
                    fileName="${basedir}/logs/own-logfile.csv"
                    archiveFileName="${basedir}/logs/archives/own-log.{#}.csv"
                    archiveEvery="Day"
                    archiveNumbering="Date"
                    archiveDateFormat="yyyyMMdd"
                    maxArchiveFiles="28"
                    concurrentWrites="true"
                    keepFileOpen="false"
                    encoding="utf-8">
                <layout xsi:type="CSVLayout">
                    <column name="time" layout="${longdate}" />
                    <column name="logger" layout="${logger}" />
                    <column name="authtype" layout="${aspnet-user-authtype}" />
                    <column name="identity" layout="${aspnet-user-identity}" />
                    <column name="level" layout="${uppercase:${level}}" />
                    <column name="message" layout="${message} ${exception:format=ToString,StackTrace}" />
                </layout>
            </target>
        </target>
        <target xsi:type="Null" name="blackhole" />
    </targets>

    <rules>
        <!--All logs, including from Microsoft-->
        <logger name="*" minlevel="Debug" writeTo="allfile" />

        <!--Skip Microsoft logs and so log only own logs-->
        <logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
        <logger name="*" minlevel="Debug" writeTo="ownFile" />    
    </rules>
</nlog>

我有并发写入true和keepFileOpen false这似乎是必要的,因为Kestrel在Linux上分支多个dotnet进程。

这是一个错误还是我的配置不正确?

0 个答案:

没有答案
相关问题