I am facing one issue since log time, How to resolve disk space issue in app server share point 2013. i have deleted the log files frequently. how to delete log files every two days automatically.


Couple of options:

  1. change the path of Log files from system drive(from c drive) to non system. Now even this drive full but still sharepoint and os will work.
  2. if you enable the verbose logging, please turn it off and switch back to "reset to default" from central admin > Configure Diagnostic logging.
  3. You can also restrict the number of logs files as well as number of days from Configure Diagnostic logging.
| improve this answer | |
  • Even after restricting the log size as well as number of days, it stores the logs beyond the log size and the days specified. – Sohail Shaikh Oct 29 '18 at 12:47

The prospected way to create a console application.

Apply the logic as per below:

  • Access the files inside the logs folder.
  • Loop through each file in the folder.
  • Check if file is older than two days.
  • If yes, then delete the file.

Once the console application with above logic is created and tested you can set a task scheduler. The task scheduler should run the console application once in a day. You can set the time in off hours (which is best practice to perform anything in SharePoint).

Here the MSDN link introducing the scheduler.

Hope this helps..!!

| improve this answer | |

You can shrink the content database's *.log files from sql server management studio.
First search for that *.ldf file where its consuming more space.

I also have written the console appln[SP 2010] for removing the *.log files from logs folder, you can have this as a scheduler in the windows server an execute. You can change the folder name from 14 to 15.

     #region references
       using System;
       using System.Configuration;
      using System.IO;
      using System.Collections;
       using System.Collections.Generic;
        using System.IO.Ports;
         using System.Data;
          using System.Data.Common;
            using System.Net;
          using System.Linq;
        using System.Text;
        using System.Web;
         using System.Web.Configuration;

     using System.Web.Mail;
     #endregion references

   #region LogsDeleteConsoleApplication
     namespace LOGSDeleteConsoleApp
 public class LOGSDeleteConsoleProgram
     bool isDeleted = false;
    private static string[] ServerPaths = new string[1];
    int freeSpaceinDrive = 3;
    int hoursofInterval = 1;
    int lastModfiedTimeDiffInMinutes = 40;

    private string _mailTo =  

    private string  _mailSubject =string.Empty;
    private string _mailBody = string.Empty;
    public string strIPAddressofSMTP = "";
      public string curServerName = string.Empty;
      static void Main(string[] args)
        LOGSDeleteConsoleApp.LOGSDeleteConsoleProgram objLogsDelete = new 
         ServerPaths[0] = @"C:\Program Files\Common Files\Microsoft 
          Shared\Web Server Extensions\14\LOGS";
        foreach (string prodServerPaths in ServerPaths)

    /// <summary>
    /// </summary>
    /// <returns></returns>
    protected void DeleteLogsFrom1214HIVE(string  productionServerPaths)
            TimeSpan tsdiff;
            curServerName = 
            DateTime currentTime = DateTime.Now;
            DateTime targetFileTime;
            string[] fileEntries = 
             Directory.GetFiles(productionServerPaths, "*.log", 
            DirectoryInfo logsDirecInfo = new 
            DriveInfo objDriveinfo = new DriveInfo(@"C:\");
            long avfreespace = objDriveinfo.AvailableFreeSpace;
            if (objDriveinfo.AvailableFreeSpace / System.Math.Pow(1024, 
         3) < freeSpaceinDrive) 
                catch(Exception myexp)

            if (fileEntries.Length > 0)
                foreach (FileSystemInfo filesinfo in 
                    if (((filesinfo.Extension.ToString() == ".log") || 
           (filesinfo.Extension.ToString()) == ".usage") && 
                        targetFileTime = filesinfo.LastWriteTime;

                        tsdiff = currentTime - targetFileTime;

                        if (((tsdiff.Hours * 60) + tsdiff.Minutes) > 
                        #region commmneted code
                        /*      */
                        #endregion commmneted code
          catch (Exception edd)
            //SharepointLogger.ErrorLogging(edd.Message.ToString() + "\n" 
      #region sendmail

     public void  SendMailAboutFreeSpace()

        MailMessage mailMessage = new MailMessage();
        mailMessage.From = "d@d.com";
         mailMessage.To = 
        mailMessage.Cc = 
        mailMessage.Subject = @"Low Disk Space Warning in C:\ driver of 
           SharePoint Server"; 
        mailMessage.Body = " Hello!!! You are running out of disk space 
          on server C:\\.To free space on this drive by deleting old or 
        unnecessary files from the Servers"; 
        mailMessage.BodyFormat = MailFormat.Html;
        SmtpMail.SmtpServer = strIPAddressofSMTP;  
        catch (Exception edd)
          SharepointLogger.ErrorLogging(edd.Message.ToString() + "\n" + 
           }  }}
        #endregion LogsDeleteConsoleApplication
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.