GithubHelp home page GithubHelp logo

gippper / writelogentry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from msadministrator/writelogentry

0.0 0.0 0.0 15 KB

A PowerShell helper function to create and write information to a log file

License: MIT License

PowerShell 100.00%

writelogentry's Introduction

WriteLogEntry

A PowerShell helper function to create and write information to a log file

Synopsis

Used to create and output information from functions

DESCRIPTION

This function will write to a log file. You can specify if the log type is: Informational (Info) Debugging (Debugging) Error (Error) This function will by default create a log file in the parent folder of the calling scope, but you can specify a seperate log location if you choose.

$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(‘.\’)\log.log

The default parameter set for this function is the Info logging, but there are 2 other sets Debug Error

EXAMPLE

Function call

Write-LogEntry -Info 'This is an informational log event'
Output
20170401T055438 [INFO]: This is an informational log event

EXAMPLE

Function call

Write-LogEntry -Debugging 'This is an debugging log event'
Output
20170401T055440 [DEBUG]: This is an debugging log event

EXAMPLE

Function call
Write-LogEntry -Error 'This is an error log event'
Output
20170401T055442 [ERROR]: This is an error log event

EXAMPLE

Function call
try { 
   do-something 
} catch { 
   Write-LogEntry -Error 'This is an error log event' -ErrorRecord $Error[0] 
}
Output
20170401T055444 [ERROR]: This is an error log event
20170401T055444 [ERROR]: The term 'do-something' is not recognized as the name of a cmdlet, `
                         function, script file, or operable program. Check the spelling of the name, `
                         or if a path was included, verify that the path is correct and try again. `
                         (CommandNotFoundException: :1 char:7)

INPUTS

System.String
System.Management.Automation.ErrorRecord

NOTES

Name: Write-LogEntry Created by: Josh Rickard Created Date: 04/01/2017

FUNCTIONALITY

Write-LogEntry is a PowerShell helper function that will accept or create a log file and add strings based on severity, as well as parse $error[0] records for easy interpretation and readability.

writelogentry's People

Contributors

msadministrator avatar admoseley avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.