0
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);

    }
}

App.Config

<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

Please check above code. It write logs only once when we do deployment on server after that it did not write any logs in MyLogs.txt file.

RajeshVerma
  • 1,087
  • 9
  • 13

1 Answers1

0

It write logs only once when we do deployment on server after that it did not write any logs in MyLogs.txt file.

I tested your code and I found my log file under D:\home\site\wwwroot\app_data\jobs\continuous\{WebjobName}\logs in KUDU.

enter image description here

Also, if you would use customized path, you could set the file value like this:

<file value="D:\home\data\logs\log.log" />

You also could find it in KUDU. enter image description here

The App.config file is as follow, you could refer to it.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net "/>
  </configSections>
  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender,log4net">
      <file value="./logs/log.log" />
      <appendToFile value="true" />
      <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline" />
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO" />
        <levelMax value="FATAL" />
      </filter>
    </appender>
    <root>
      <level value="ALL"/>
      <appender-ref ref="FileAppender"/>
    </root>
  </log4net>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
</configuration>
Joey Cai
  • 18,968
  • 1
  • 20
  • 30