I am using Provide Hosted App & created a web job (Hosted in Azure)which configure my SharePoint Online site collection. This web job uses CSOM. It is working properly but after 30 minute it shows error :
Exception :The remote server returned an error: (401) Unauthorized. Server        : RD00155D31D5E0 Parent Method Name: CreateAndUploadLogFile Error Method     : GetResponse Method Tree      : GetResponse ,Execute ,ExecuteQueryToServer ,ExecuteQuery ,ExecuteQuery ,ExecuteQuery ,CreateAndUploadLogFile , Assembly Name    : BizPortal.RemoteProvisioning.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Error Type       : System.Net.WebException Message          : The remote server returned an error: (401) Unauthorized. Source           : System Target           : System.Net.WebResponse GetResponse() Stack Trace      :   at System.Net.HttpWebRequest.GetResponse() at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
Sounds like you aren’t authenticating correctly against SharePoint Online when trying to upload the log file.
Did you get any solution for this? Please share.