我有一个控制台应用程序,其中包含 log4net(V-2.0.15)用于日志。配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<connectionStrings>
</connectionStrings>
<appSettings>
<!--<add key="log4net.Internal.Debug" value="true"/>-->
</appSettings>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\logs1\log.txt" />
<encoding value="utf-8" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<!--<maxSizeRollBackups value="10" />
<maximumFileSize value="100MB" />
<staticLogFileName value="true" />-->
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="All" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
C# 代码如下:
private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
static void Main(string[] args)
{
try
{
///Coding...
}
catch (Exception ex)
{
Log.Error("------- Error Message : " + ex.Message + "------- StackTrace : " + ((ex.StackTrace != null) ? ex.StackTrace.ToString() : ""));
}
}
现在我将该控制台应用程序发布到本地文件夹,并在创建“任务计划程序 -> 基本任务”时选择 exe 文件并创建它。但它没有做任何事情。我在这里缺少什么???