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:
- 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.
- if you enable the verbose logging, please turn it off and switch back to "reset to default" from central admin > Configure Diagnostic logging.
- You can also restrict the number of logs files as well as number of days from Configure Diagnostic logging.
-
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..!!
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 =
"a@a.com;p@p.com;";
private string _mailSubject =string.Empty;
private string _mailBody = string.Empty;
public string strIPAddressofSMTP = "158.157.123.231";
public string curServerName = string.Empty;
static void Main(string[] args)
{
LOGSDeleteConsoleApp.LOGSDeleteConsoleProgram objLogsDelete = new
LOGSDeleteConsoleProgram();
ServerPaths[0] = @"C:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\14\LOGS";
foreach (string prodServerPaths in ServerPaths)
{
objLogsDelete.DeleteLogsFrom1214HIVE(prodServerPaths);
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
protected void DeleteLogsFrom1214HIVE(string productionServerPaths)
{
try
{
TimeSpan tsdiff;
curServerName =
System.Configuration.ConfigurationManager.AppSettings
["CURR_SERVER_NAME"].ToString();
DateTime currentTime = DateTime.Now;
DateTime targetFileTime;
string[] fileEntries =
Directory.GetFiles(productionServerPaths, "*.log",
SearchOption.TopDirectoryOnly);
DirectoryInfo logsDirecInfo = new
DirectoryInfo(productionServerPaths);
DriveInfo objDriveinfo = new DriveInfo(@"C:\");
long avfreespace = objDriveinfo.AvailableFreeSpace;
if (objDriveinfo.AvailableFreeSpace / System.Math.Pow(1024,
3) < freeSpaceinDrive)
{
try
{
SendMailAboutFreeSpace();
}
catch(Exception myexp)
{
}
}
if (fileEntries.Length > 0)
{
foreach (FileSystemInfo filesinfo in
logsDirecInfo.GetFiles())
{
if (((filesinfo.Extension.ToString() == ".log") ||
(filesinfo.Extension.ToString()) == ".usage") &&
(filesinfo.Name.ToString().Contains(curServerName)))
{
targetFileTime = filesinfo.LastWriteTime;
tsdiff = currentTime - targetFileTime;
if (((tsdiff.Hours * 60) + tsdiff.Minutes) >
lastModfiedTimeDiffInMinutes)
{
filesinfo.Delete();
}
#region commmneted code
/* */
#endregion commmneted code
}
}
}
else
{
}
}
catch (Exception edd)
{
//SharepointLogger.ErrorLogging(edd.Message.ToString() + "\n"
+
edd.StackTrace.ToString());
}
}
#region sendmail
public void SendMailAboutFreeSpace()
{
try
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = "d@d.com";
mailMessage.To =
system.Configuration.ConfigurationManager.
AppSettings["MailMessage_To"].ToString();
mailMessage.Cc =
System.Configuration.ConfigurationManager.
AppSettings["MailMessage_CC"].ToString();
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;
SmtpMail.Send(mailMessage);
}
catch (Exception edd)
{
SharepointLogger.ErrorLogging(edd.Message.ToString() + "\n" +
edd.StackTrace.ToString());
}
#endregion
} }}
#endregion LogsDeleteConsoleApplication