MOSS 2007 Maintenance and Trace logs Removal

By default, Office SharePoint Server 2007 trace logging is enabled in Central Administration > Operations > Diagnostic Logging and the log files are stored at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS on your front-end web server.
ManagingMOSS

Without changing the verbosity of logging via event throttling settings, or the number of minutes before creating a new log file, each log file is around 50 MB. By default, MOSS keeps 48 of these files, spanning 2 days for a grand total of around 2.4 GB.

I have changed the default path location to a different drive in the Trace Log section and decrease the number of log files to 12 to be used for 24hrs(1440 min).

Here are the settings on the diagnostic logging page:
Diagnostic Logging

The log file related to SharePoint_Config database can grow to huge sizes without a maintenance plan, or at the very least setting databases to backup in “simple” mode will dramatically reduce the size of the logs.

MOSS 2007 server installation has a log file called WSS_AdminService.log held in C:\Documents and Settings\Default User\Local Settings\Temp. This is just a log file and it is being written at regular intervals increasing its size. Worse still, because it’s in the C:\Documents and Settings\Default User folder it gets duplicated when a new user logs onto the server console. You can safely delete this file.

The following is a C# console application code which can make the administrator work easier. Administrator can create the console application using the following code and schedule it every alternate day to delete the above mentioned logs automatically. This way you can keep your server disk usage low.
—————————————–

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.ComponentModel;
  5. using System.Runtime.InteropServices;
  6. namespace TemporaryFilesRemoval
  7. {
  8.     class Program
  9.     {
  10.         /// <summary>
  11.         /// The main entry point for the application.
  12.         /// </summary>
  13.         [STAThread]
  14.         static void Main(string[] args)
  15.         {
  16.             Console.Title = “Temporary LOG Files Removal”;
  17.             DeleteFiles(“C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\LOGS”, “*.log”);
  18.             DeleteFolder(“C:\\Program Files\\Common Files\\Microsoft Shared\\web server extensions\\12\\LOGS”, “*.log”);
  19.             DeleteFiles(“D:\\Sharepoint Logs”, “*.log”);
  20.             DeleteFiles(“C:\\Documents and Settings\\Default User\\Local Settings\\Temp”, “*.log”);
  21.         }
  22.         static void DeleteFolder(string rootfolder, string filter)
  23.         {
  24.             try
  25.             {
  26.                 string[] directories = System.IO.Directory.GetDirectories(rootfolder);
  27.                 Console.WriteLine(string.Format(“Total {0} directories in {1}”, (directories.Length), rootfolder));
  28.                 foreach (string dir in directories)
  29.                 {
  30.                     DeleteFiles(dir, filter);
  31.                     DeleteFolder(dir, filter);
  32.                     try
  33.                     {
  34.                         Console.WriteLine(string.Format(“Deleting directory : {0}”, dir));
  35.                         System.IO.Directory.Delete(dir);
  36.                         Console.WriteLine(string.Format(“{0} has been deleted.”, dir));
  37.                     }
  38.                     catch (Exception ex)
  39.                     {
  40.                         Console.WriteLine(string.Format(“Error : {0}”, ex.Message));
  41.                         Console.WriteLine();
  42.                     }
  43.                 }
  44.             }
  45.             catch (Exception ex)
  46.             {
  47.                 Console.WriteLine(string.Format(“Error : {0}”, ex.Message));
  48.                 Console.WriteLine();
  49.             }
  50.         }
  51.         static void DeleteFiles(string folder, string filter)
  52.         {
  53.             string[] files = null;
  54.             try
  55.             {
  56.                 if (!string.IsNullOrEmpty(filter))
  57.                 {
  58.                     files = System.IO.Directory.GetFiles(folder, filter);
  59.                 }
  60.                 else
  61.                 {
  62.                     files = System.IO.Directory.GetFiles(folder);
  63.                 }
  64.                 Console.WriteLine(string.Format(“Total {0} file(s) in {1}”, (files.Length), folder));
  65.                 Console.WriteLine();
  66.                 foreach (string file in files)
  67.                 {
  68.                     Console.WriteLine(string.Format(“Deleting {0}”, file));
  69.                     System.IO.File.Delete(file);
  70.                     Console.WriteLine(string.Format(“{0} has been deleted.”, file));
  71.                     Console.WriteLine();
  72.                 }
  73.             }
  74.             catch (Exception ex)
  75.             {
  76.                 Console.WriteLine(string.Format(“Error : {0}”, ex.Message));
  77.                 Console.WriteLine();
  78.             }
  79.         }
  80.     }
  81. }
    —————————————–

I have included a word version of it here -LogClean or Alternatively http://technobuff.pastebin.com/f61f70e48

Please note that in the above code, I have also included my new path of trace logs i.e, (“D:\\Sharepoint Logs”, “*.log”);

You can also use the same application to clean up your Temporary ASP.NET Files. Just include the path, default will be C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

DeleteFiles(“C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\Temporary ASP.NET Files”, string.Empty);
DeleteFolder(“C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\Temporary ASP.NET Files”, string.Empty);

About these ads

11 thoughts on “MOSS 2007 Maintenance and Trace logs Removal

  1. Pingback: Many users using single VM machine , running out of space on C: « Jasper Blog

  2. Have you found any Microsoft documentation on this file, why it is written, why it is put in such a place as to cause servers to fail, and Microsoft’s recommendation on handling this bug?

    • from http://technet.microsoft.com/en-us/library/cc262177.aspx#section4

      “Trace log files can help you to troubleshoot issues related to configuration changes of the Windows SharePoint Services Search service. The trace log can also be useful for analyzing problems that might occur. For example, you can use events that are written to the trace log to identify what configuration changes were made in Office SharePoint Server 2007 before the problem occurred.

      Because problems related to configuration changes are not always immediately discovered, we recommend that you save all trace log files that the system creates on any day that you make any configuration changes related to the search service. Store these log files for an extended period of time in a safe location that will not be overwritten.”

    • not sure of the purpose of the file. May be someone at Microsoft forgot to switch off the debug option for WSSADMIN.EXE. thats my best guess :)

  3. Yes, it seems like a bad bug, but what is even more surprising, is that there is no apparent evidence that Microsoft has even addressed it, much less fixed it.

    Does MOSS2010 have this bug?

  4. Pingback: IT support blog

  5. It. There is a deplartment on Free and Low cost Help whbich can’t allow specific
    referrals, but which poknts you in the right direction. Terreitorial aggression is
    common in canines.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s