|
| 1 | +<div align="center"> |
| 2 | + |
| 3 | +<h1 align="center"><b>Write-Log</b></h1> |
| 4 | + |
| 5 | + <p align="center"> |
| 6 | + A simple project to easily add a log to your projects |
| 7 | + <br /> |
| 8 | + <a href="https://github.com/captainqwerty/Write-Log/releases">Releases</a> |
| 9 | + <a href="https://github.com/captainqwerty/Write-Log/issues">Report Bug</a> |
| 10 | + </p> |
| 11 | +</div> |
| 12 | + |
| 13 | +<!-- ABOUT THE PROJECT --> |
| 14 | +## About The Project |
| 15 | + |
| 16 | +This project was to just offer people a easy way to quickly add the ability to output a nice, simple log within their own projects. There are two versions in this project known as the *Class Version* and the *Module Version*. |
| 17 | + |
| 18 | +### Class Version |
| 19 | + |
| 20 | +The class Version is the preffered version however this version is limited to PowerShell Version 5.0 and greater and utilises the *Using* statement. |
| 21 | + |
| 22 | +### Module Version |
| 23 | + |
| 24 | +The Module Version is available for those prefering to use *Import-Module* and those using older versions of PowerShell as the Class version will not work on PowerShell versions prior to 5.0. |
| 25 | + |
| 26 | +<p align="right">(<a href="#top">back to top</a>)</p> |
| 27 | + |
| 28 | +<!-- GETTING STARTED --> |
| 29 | +## Getting Started |
| 30 | + |
| 31 | +This is an example of how you may give instructions on setting up your project locally. |
| 32 | +To get a local copy up and running follow these simple example steps. |
| 33 | + |
| 34 | +### Prerequisites |
| 35 | + |
| 36 | +This is an example of how to list things you need to use the software and how to install them. |
| 37 | +* PowerShell version 2.0 or greater - Module Version. |
| 38 | +* PowerShell version 5.0 or greater - Either version. |
| 39 | + |
| 40 | +### Installation of Class Version |
| 41 | + |
| 42 | +1. Download the <a href="https://github.com/captainqwerty/Write-Log/release">latest release</a>. |
| 43 | +2. Place the "Write-Log" folder in your project's folder or in a location the script can access under the context it will be ran. |
| 44 | +3. Add the Using satement pointing to the Write-Log-Class.psm1 file, please note using statements must be the very first lines of your script. In this example the Write-Log folder containing the file is in the root folder with the script calling it. |
| 45 | +```ps1 |
| 46 | +using module ".\Write-Log\Write-Log-Class.psm1" |
| 47 | +``` |
| 48 | +4. See <a href="#usage-of-the-class-version">Class Version Usage</a> section for examples on how to configure the log location and add enteries. |
| 49 | + |
| 50 | +### Installation of Module Version |
| 51 | + |
| 52 | +1. Download the <a href="https://github.com/captainqwerty/Write-Log/releases">latest release</a>. |
| 53 | +2. Ensure the Write-log.psm1 remains in a folder called "Write-Log" and place the Write-Log folder in your project's folder or in a location the script can access under the context it will be ran. |
| 54 | +3. Import the Module. In this example the Write-Log folder is in the root of the project folder. |
| 55 | +```ps1 |
| 56 | +$module = "$psscriptroot\Write-Log" |
| 57 | +if(!(test-path $module)){ |
| 58 | + write-host "$module not found" -ForegroundColor Red |
| 59 | + exit |
| 60 | +} |
| 61 | +Import-Module $module |
| 62 | +``` |
| 63 | +4. See <a href="#usage-of-the-module-version">Module Version Usage</a> section for examples on how to configure the log location and add enteries. |
| 64 | +5. Add the Remove-Module line to the bottom of your script. |
| 65 | +```ps1 |
| 66 | +Remove-Module Write-Log |
| 67 | +``` |
| 68 | + |
| 69 | +<p align="right">(<a href="#top">back to top</a>)</p> |
| 70 | + |
| 71 | +<!-- USAGE EXAMPLES --> |
| 72 | +## Usage of the Class Version |
| 73 | +```ps1 |
| 74 | +using module ".\Class\Write-Log\Write-Log-Class.psm1" |
| 75 | +
|
| 76 | +$Log = [WriteLog]::New("C:\Example\mylog.log") |
| 77 | +
|
| 78 | +$Log.AddInfo("Something occured that was wroth making an info log about") |
| 79 | +$Log.AddError("There was a huge error!") |
| 80 | +$Log.AddWarning("Oh dear I should really warn you about this!") |
| 81 | +$Log.AddEntry("Testing","Test Severity") #This method is hidden but can be used for custom severities |
| 82 | +``` |
| 83 | +The below example shows having mutliple Write-Log objects to store different types or log enteries in different logs. |
| 84 | + |
| 85 | +```ps1 |
| 86 | +using module ".\Class\Write-Log\Write-Log-Class.psm1" |
| 87 | +
|
| 88 | +$InfoLog = [WriteLog]::New("C:\Example\Info.log") |
| 89 | +$ErrorLog = [WriteLog]::New("C:\Example\Errors.log") |
| 90 | +$WarningLog = [WriteLog]::New("C:\Example\Warning.log") |
| 91 | +
|
| 92 | +$InfoLog.AddInfo("Something occured that was wroth making an info log about") |
| 93 | +$ErrorLog.AddError("There was a huge error!") |
| 94 | +$WarningLog.AddWarning("Oh dear I should really warn you about this!") |
| 95 | +``` |
| 96 | + |
| 97 | +## Usage of the Module version |
| 98 | +```ps1 |
| 99 | +$module = "$psscriptroot\Module\Write-Log" |
| 100 | +if(!(test-path $module)){ |
| 101 | + write-host "$module not found" -ForegroundColor Red |
| 102 | + exit |
| 103 | +} |
| 104 | +Import-Module $module |
| 105 | +
|
| 106 | +$logLocation = "C:\Example\Log.log" |
| 107 | +
|
| 108 | +write-log "This is an example Info" -logLocation $logLocation |
| 109 | +write-log "This is an example Error" -severity "Error" -logLocation $logLocation |
| 110 | +write-log "This is an example Warning" -severity "Warning" -logLocation $logLocation |
| 111 | +
|
| 112 | +Remove-Module Write-Log |
| 113 | +``` |
| 114 | +Below is an example of having seperate logs for Info, Error and Warning enteries. |
| 115 | +```ps1 |
| 116 | +$module = "$psscriptroot\Module\Write-Log" |
| 117 | +if(!(test-path $module)){ |
| 118 | + write-host "$module not found" -ForegroundColor Red |
| 119 | + exit |
| 120 | +} |
| 121 | +Import-Module $module |
| 122 | +
|
| 123 | +$InfoLog = "C:\Example\Log.log" |
| 124 | +$ErrorLog = "C:\Example\Errors.log" |
| 125 | +$WarningLog = "C:\Example\Warning.log" |
| 126 | +
|
| 127 | +write-log "This is an example Info" -logLocation $InfoLog |
| 128 | +write-log "This is an example Error" -severity "Error" -logLocation $ErrorLog |
| 129 | +write-log "This is an example Warning" -severity "Warning" -logLocation $WarningLog |
| 130 | +
|
| 131 | +Remove-Module Write-Log |
| 132 | +``` |
| 133 | +<p align="right">(<a href="#top">back to top</a>)</p> |
| 134 | + |
| 135 | +<!-- CONTRIBUTING --> |
| 136 | +## Contributing |
| 137 | + |
| 138 | +Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. |
| 139 | + |
| 140 | +If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". |
| 141 | +Don't forget to give the project a star! Thanks again! |
| 142 | + |
| 143 | +1. Fork the Project |
| 144 | +2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) |
| 145 | +3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) |
| 146 | +4. Push to the Branch (`git push origin feature/AmazingFeature`) |
| 147 | +5. Open a Pull Request |
| 148 | + |
| 149 | +<p align="right">(<a href="#top">back to top</a>)</p> |
0 commit comments