public class Program
{
private static readonly log4net.ILog Log = log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
static void Main()
{
log4net.Config.XmlConfigurator.Configure();
try
{
MainA().Wait();
}
catch (Exception ex)
{
Log.ErrorFormat("Failed to Delete Data, Error: {0}, Stack Trace {1}, Inner Exception {2}", ex.Message, ex.StackTrace, ex.InnerException);
}
}
public static async Task MainA()
{
Log.InfoFormat("Service started at {0}", DateTime.UtcNow);
WebJobService srv = new WebJobService();
await srv.DeleteData();
Log.InfoFormat("Service ended at {0}", DateTime.UtcNow);
}
}
应用程序配置
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
请检查上面的代码。当我们在服务器上进行部署时,它只写入一次日志,之后它没有在 MyLogs.txt 文件中写入任何日志。