Showing posts with label #twitter @nakedpowershell. Show all posts
Showing posts with label #twitter @nakedpowershell. Show all posts

Monday, October 31, 2016

Tweaks to Write-LogEntry

Tweaks to Write-LogEntry that was posted to Twitter by Trevor Sullivan @pcgeek86

His original PowerShell code:
function Write-LogEntry {
    [CmdletBinding()]
    param (
    [string] $Message,
    [string] $Severity
)
$CallStack = Get-PSCallStack
$LogMessage = '{0} {1}: {2}: {3}' -f (Get-Date -Format u), $CallStack[1].FunctionName, $Severity, $Message
Add-Content -Path c:\temp\logfile.log -Value $LogMessage
}
function LogTester {
 [CmdletBinding()]
    param (
    )
    Write-LogEntry -Message Testing1 -Severity Information
    Write-LogEntry -Message Testing2 -Severity Warning
    Write-LogEntry -Message Testing3 -Severity Error
}
LogTester
My tweaks to the original PowerShell code:
Function Write-LogEntry {
    [CmdletBinding()]
    param (
    [string] $Message,
    [string] $Severity,
    [string] $Step
)
$CallStack = Get-PSCallStack
$LogMessage = '{0},{1},{2},{3},{4},{5}' -f $env:computername,((get-date).ToUniversalTime()), $CallStack[1].FunctionName, $Severity, $Message, $Step
Add-Content -Path c:\temp\logfile.csv -Value $LogMessage
}
function LogTester {
 [CmdletBinding()]
    param (
    )
    Write-LogEntry -Message Testing1 -Severity Information -Step 10
    Write-LogEntry -Message Testing2 -Severity Warning -Step 20
    Write-LogEntry -Message Testing3 -Severity Error -Step 55
}
LogTester
I did the following:

Changed the format of the date to UTC that was readable by Excel
Changed the output to a .CSV format and adding commas to the -f
Added the computername as the first entry in the text log
Added a parameter Step to the log

When I am consuming logs, lots of logs, I like tools like Excel to slice, dice, sort, and filter the data for me in a visual way.

When I write logging functions, I like to know what step tripped the log entry. So in my applications I set $Step to a number that is incremental from the last step I used this variable.

For example I set my step to 10 for the variable initially at the beginning of the application. Then at the start of each major piece of logic where I could trip the logging I increment the step by 10.

The steps then help me narrow down where in code the logging got tripped.

A future version of this could be to load the log into a SQL Table and also account for multiple applications writing to the same log.

Thank Trevor !!


Wednesday, August 19, 2015

Monday, August 17, 2015

Friday, August 7, 2015

Wednesday, July 29, 2015

Tuesday, July 28, 2015

#OpenSSH #flaw #infosec #SSH OpenSSH Vulnerability Exposes Servers to Brute Force Attacks | http://t.co/YsxpNinz78 http://t.co/ViiSjs6jly


from Twitter https://twitter.com/nakedpowershell

#TFBuild #TFS #ALM Enabling Verbose Output in Team Foundation Build Logs | Team Build | Software Development, 42,... http://t.co/yuYmjkHwbD


from Twitter https://twitter.com/nakedpowershell

#PHP #flaw #security Many High-Profile Firms Using Vulnerable PHP File Manager: Researcher | http://t.co/YsxpNinz78 http://t.co/0Q0XxKlbVg


from Twitter https://twitter.com/nakedpowershell

#infosec #flaw #MongoDB Configuration Issue Exposes 30,000 MongoDB Instances: Researcher | http://t.co/YsxpNinz78 http://t.co/bDwveTTuuq


from Twitter https://twitter.com/nakedpowershell

Monday, July 27, 2015

Friday, July 24, 2015

#VS2015 Code Metrics PowerTool for Visual Studio 2015 Available on Microsoft Download Center - Microsoft... http://t.co/uzMsj0oRFs


from Twitter https://twitter.com/nakedpowershell

#PowerBI #TFS Reporting on Work Items with Power BI - Microsoft Application Lifecycle Management - Site Home -... http://t.co/v8Rp35e2Uv


from Twitter https://twitter.com/nakedpowershell

Friday, July 17, 2015

#SQLServer #PowerShell This is Sparta...n SQL!: Scripting out statistics http://t.co/DBtlZ25Xx4


from Twitter https://twitter.com/nakedpowershell

#SQLServer HOW TO: Recreate SQL Server Statistics In a Different Environment http://t.co/JQQQWbPvrz


from Twitter https://twitter.com/nakedpowershell

#PowerShell #PSDSC #RM #TFS #ALM Reflections on DSC for Release Management http://t.co/Al88evqZ89


from Twitter https://twitter.com/nakedpowershell

#Agile #TFS2015 #PowerShell #TFS Enable SAFe Features in Existing Team Projects After Upgrading to TFS 2015 http://t.co/043uyOwAAi


from Twitter https://twitter.com/nakedpowershell

Thursday, July 16, 2015