1

If I have this:

Get-ChildItem -Path $BACKUP_REG_PATH >> $TOT_LOG_FILE

I will get a fine list in my log file like this:

Directory: C:\WS\BACKUP\xxxx-Reg


Mode                LastWriteTime     Length Name                                                                     
----                -------------     ------ ----                                                                     
-a---        2016-05-17     11:04     494018 xxxxxx_REGISTRY_EVENTLOG__2016-05-17__11_04_38.reg                       
-a---        2016-05-17     11:08     494018 xxxxxx_REGISTRY_EVENTLOG__2016-05-17__11_08_59.reg                       
-a---        2016-05-17     11:10     494018 xxxxx_REGISTRY_EVENTLOG__2016-05-17__11_10_31.reg                       

I want to do this for NLog instead but I don't know how to get a nice list as above.

If I do this:

$regtxt=Get-ChildItem -Path $BACKUP_REG_PATH 
$LOGGER.Trace("$regtxt");

I only get a long list on the same row with the Name column.

Any ideas how to solve this?

Julian
  • 33,915
  • 22
  • 119
  • 174
user1423277
  • 109
  • 2
  • 13

1 Answers1

1

I don't know NLog but the Trace method probably output the trace in a single line. You could iterate over each item using the Foreach-Object cmdlet and write a trace:

Get-ChildItem -Path $BACKUP_REG_PATH | Foreach-Object {
    $LOGGER.Trace($_);
}

Note: This will not output the name column, you may have to trace this yourself.

To solve this, you could pipe the output to the Out-String cmdlet which will give you a single string. You then have to split the string by [System.Environment]::NewLine to get an array to iterate over it:

((Get-ChildItem | select -first 4 | Out-String) -split [System.Environment]::NewLine) | 
    ForEach-Object {
        $LOGGER.Trace($_);
    } 
Julian
  • 33,915
  • 22
  • 119
  • 174
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172