Enabling Debug Log on an ARS server

To enable the debug log on an ARS server you add a new DWORD value ‘debug’ to the Enterprise Directory Manager key and set it to 1.

Watch out though the log gets large very quickly and the default location is the install directory which is probably on your C drive.  In other words it’s about to crash your server because you will run out of space on the C: drive. 

Why Dell didn’t dell allow this to be redirected?  Also they should break the file up into smaller chunks.  

Realising the second issue Dell do provide a script to limit the log file size.  I modified this script a little to allow me to have a little more control over the log files. 

My script uses a loop to prompt you to archive the log and also automates splitting the log into smaller chunks.  I plan to use a powershell job to allow the script to keep running in the back ground but this version just waits for you to respond.  Assuming I get it working using a powershell job then I can also automate a maximum size.

it also does some other stuff like deleting any existing logs before you start and also it allows you to name the files using the incident number.  It’s written as a standalone function but I’ve included the code I used to manage enabling, capturing and archiving the logs ready to send off to Dell.

The function has two switches -stop to stop the logging and -initialise which will start the logging and delete any existing logfile.

I can see that I didn’t quite finish writing a standalone function so I’ll need to revisit it later when I have time. It’s easy to fix but I have some objectives to update before my end of year review 😦 so it will have to be some other time. It’s fully functional though so you can always take this as it is and modify it to fit your requirements.



Function Move-DSLog {
 param (
  $outputLogFileName,
  $dsLogFile,
  $regkey,
  [switch]$initialise,
  [switch]$stop
 )
 Write-host "Debug currently set to : $(Get-ItemProperty -path $regkey -name Debug | select -ExpandProperty debug)"
 if ( $initialise ) {
  if ( $(Get-ItemProperty -path $regkey -name Debug | select -ExpandProperty debug) -eq 1 ) {
   Write-Host "DEBUG already enabled"
   Write-Host "Disabling Debug so we can clear any old log files"
   set-itemproperty -path $regkey -name Debug -value 0
   sleep -Seconds 1
  }
  if ( $(Get-ItemProperty -path $regkey -name Debug | select -ExpandProperty debug) -eq 0 ) {
   Write-Host "Deleting any existing log file"
   if ( Test-Path $dsLogFile ) {
    Remove-Item $dsLogFile
   }  
   Write-Host "Setting DEBUG reg Key to 1"
   try { 
    set-itemproperty -path $regkey -name Debug -value 1 
   }
   catch { 
    Write-Host "FATAL ERROR: Failed to set debug reg key to 1 "
    exit 
   }
  }
  else {
   Write-Host "FATAL ERROR: Failed to set debug reg key to 0"
   exit   
  }
  Return 
 }
 if ( Test-Path $dsLogFile ) {
  Write-Host "Moving DEBUG Log"
  try { 
   set-itemproperty -path $regkey -name Debug -value 0 
   sleep -Seconds 1
  }
  catch { 
   Write-Host "FATAL ERROR: Failed to set debug reg key to 0" 
   exit 
  }
  if ( Test-Path $dsLogFile )  {
   $fileMovedSuccesfully = $false
   $loopCount = 0 
   while ($fileMovedSuccesfully -eq $false ) {
    $loopCount++
    try { 
     move-item $dsLogFile $outputLogFileName -ErrorAction SilentlyContinue
     $fileMovedSuccesfully = $true
    }
    catch { 
     $fileMovedSuccesfully = $false
    }
    if ( $loopCount -gt 10 ) {
     Write-Host "FATAL ERROR: unable to move logfile!"
     exit
    }
   }
  }
 }
 if ( $stop ) {
  exit 
 } # stop  
 else { 
  Write-Host "Setting DEBUG reg Key to 1"
  try { 
   set-itemproperty -path $regkey -name Debug -value 1 
  }
  catch { 
   Write-Host "FATAL ERROR: Failed to set debug reg key to 1 "
   exit 
  }
 }
} # end function 
  
# user definable parameters
$maxLogFileSize = 1          # max filesize in Meg 
$regkey = "HKLM:\SOFTWARE\Aelita\Enterprise Directory Manager"
$installationFolder = Get-ItemProperty -Path $regkey | Select -Expand InstallPath
$dsLogfileName = "ds.log"
$dsLogfileName = $InstallationFolder + $dsLogfileName

$destpath = "d:\ARSDSlogs\"  # folder must exit 
$destinationFileName = "ds"  # example file name
$destinationFileName = Read-Host -Prompt "Enter the SRNumber"

 
cls
Move-DSLog -initialise -dsLogFile $dsLogfileName -regkey $regkey
$logsize = 0
$continue = $true
$logNumber = 0
while ($continue ) {
 try { 
  $info = Get-ItemProperty $dsLogfileName -ErrorAction SilentlyContinue | select -expand length 
  [int]$logsize = $info/1MB
 }
 catch { 
  $logsize = 0 
 }
 write-output "Logsize is currently $logsize"
 try { $answer = Read-Host -Prompt "Archive Log Y/N - NOTE: log file size is still growing...." }
 catch { 
  $breakPoint = 0 
 }
 if ( ( $answer -ne $null ) -and ( $answer.ToLower() -eq "y" ) ) {
  $logNumber++
  Write-Host "USER RESPONSE: $answer"
  Write-Host "Moving log to $($destpath + "DSLog-$logNumber-" +$destinationFileName + "-{0:yyyy-MM-dd-HHmm-ss}.log" -f (get-date))"
  Move-DSLog -dsLogFile $dsLogfileName -outputLogFileName $($destpath + "DSLog-$logNumber-" +$destinationFileName + "-{0:yyyy-MM-dd-HHmm-ss}.log" -f (get-date)) -regkey $regkey   
  try { $answer = Read-Host -Prompt "Continue Logging Y/N" }
  catch { 
   $breakPoint = 0 
  }
  if ( ( $answer -ne $null ) -and ( $answer.ToLower() -eq "n" ) ){
   $logNumber++
   Write-Host "USER RESPONSE: $answer"
   Write-Host "Moving log to $($destpath + "DSLog-$logNumber-" +$destinationFileName + "-{0:yyyy-MM-dd-HHmm-ss}.log" -f (get-date))"
   Write-Host "And then stopping log capture"   
   Move-DSLog -dsLogFile $dsLogfileName -outputLogFileName $($destpath + "DSLog-$logNumber-" +$destinationFileName + "-{0:yyyy-MM-dd-HHmm-ss}.log" -f (get-date)) -regkey $regkey -stop 
   exit
  }
 }
 if ( ($logsize -gt $maxLogFileSize) -and ( $logsize -ne 0 ) ) {
  $logNumber++
  Write-Host "Max log file limit exceeded...."
  Write-Host "Moving log to $($destpath + "DSLog-$logNumber-" +$destinationFileName + "-{0:yyyy-MM-dd-HHmm-ss}.log" -f (get-date))"  
  Move-DSLog -dsLogFile $dsLogfileName -outputLogFileName $($destpath + "DSLog-$logNumber-" +$destinationFileName + "-{0:yyyy-MM-dd-HHmm-ss}.log" -f (get-date)) -regkey $regkey
 }
}


Advertisements

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.