[英]NLog windows application log files not created after make an installable exe
我創建了一個Windows應用程序並將錯誤文件記錄在文本文件中,當我將其發布並作為應用程序文件記錄時,未在相應的文件夾中創建日志文件。
工作正常-轉換為安裝程序之前,該問題在可安裝exe之后發生。 任何人都可以建議做一個更好的解決方案app.config
<target name="logfile" xsi:type="File" fileName="${basedir}/DebugLog/${date:format=yyyy-MM-dd}-logFile.log" />
在應用程序配置中添加了nlog元素
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="${basedir}/DebugLog/${date:format=yyyy-MM-dd}-logFile.log" />
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile" />
<logger name="*" minlevel="Error" writeTo="email" />
</rules>
</nlog>
C#:
private void button3_Click(object sender, EventArgs e)
{
logger.Error("Some Error has occured ");
}
app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="${basedir}/DebugLog/${date:format=yyyy-MM-dd}-logFile.log" />
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile" />
<logger name="*" minlevel="Error" writeTo="email" />
</rules>
</nlog>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE,OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
不知道這是否是不好的復制粘貼作業,但是您的XML無效:
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="${basedir}/DebugLog/${date:format=yyyy-MM-dd}-logFile.log" />
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile" />
<logger name="*" minlevel="Error" writeTo="email" />
</rules>
</nlog>
應該更改為(包括end-targets-tag):
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="${basedir}/DebugLog/${date:format=yyyy-MM-dd}-logFile.log" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile" />
<logger name="*" minlevel="Error" writeTo="email" />
</rules>
</nlog>
但是啟用和檢查內部記錄器的好主意: https : //github.com/NLog/NLog/wiki/Internal-Logging
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.