Code Monkey home page Code Monkey logo

Comments (7)

jasonchester avatar jasonchester commented on August 22, 2024 1

Disregard my previous comment, cannot reproduce.

I removed the random start-sleep and saw the errors displayed...

[2019-05-22 13:19:35-04] [ERROR  ] Message n. 97
Out-File : Cannot find drive. A drive with the name 'C' does not exist.
At /Users/jason.chester/.local/share/powershell/Modules/Logging/4.1.1/targets/File.ps1:32 char:17
+         $Text | Out-File @Params
+                 ~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (C:String) [Out-File], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.OutFileCommand

from logging.

jasonchester avatar jasonchester commented on August 22, 2024

since $PSEdition isn't available before PS 5.1 a better check might be to test the property itself...

if($initialState.ApartmentState) { $true } 

from logging.

tosoikea avatar tosoikea commented on August 22, 2024

@EsOsO PowerShell/PowerShell#6908. The created InitialSessionState should be MTA by default.

from logging.

EsOsO avatar EsOsO commented on August 22, 2024

Ok, we should drop the ApartmentState assignment ad use deafult

from logging.

tosoikea avatar tosoikea commented on August 22, 2024

Okay, after some testing it seems like this is not true for all PowerShell versions...
I would include the following code snippet.

$initialState = [InitialSessionState]::CreateDefault()
if (Get-Member -InputObject $initialState -Name "ApartmentState" -MemberType Property) {
   $initialState.ApartmentState = [System.Threading.ApartmentState]::MTA
}

from logging.

tosoikea avatar tosoikea commented on August 22, 2024

@jasonchester There is a new version up for download, implementing the wanted check. Could you test the functionality for powershell core with the updated version?

from logging.

jasonchester avatar jasonchester commented on August 22, 2024

@tosoikea this works on powershell core now...

one strange thing I noticed when running the sample code

Set-LoggingDefaultLevel -Level 'WARNING'
Add-LoggingTarget -Name Console
Add-LoggingTarget -Name File -Configuration @{Path = 'C:\Temp\example_%{+%Y%m%d}.log'}

$Level = 'DEBUG', 'INFO', 'WARNING', 'ERROR'
foreach ($i in 1..100) {
    Write-Log -Level ($Level | Get-Random) -Message 'Message n. {0}' -Arguments $i
    Start-Sleep -Milliseconds (Get-Random -Min 100 -Max 1000)
}

Wait-Logging  

is that the system hung... i identified the issue as the path set here:

Add-LoggingTarget -Name File -Configuration @{Path = 'C:\Temp\example_%{+%Y%m%d}.log'}

was not valid on my mac but instead of displaying a meaningful error message, logging appears to hang. One suggestion i would have would be to validate creating a file when adding a target or at least trapping any errors when writing to a target.

Otherwise everything looked great, thanks for the help.

from logging.

Related Issues (20)

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.