gaelcolas / log4ps

PowerShell module for logging using log4net library.
Other
19 stars 9 forks source link

Logfile not created Windows 10, PS5.1, .Net 4.6.1 #2

Closed kasperbrandenburg closed 8 years ago

kasperbrandenburg commented 8 years ago

This module appears to have issues. I'm testing on Windows 10 /w anniversary update. .Net 4.6.1 is installed.

The logfile is not created, and once the script has run, the powershell promt seem to output some type of array on all subsequent commands.

Name                           Value
----                           -----
PSVersion                      5.1.14393.82
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.82
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Output from running this:

C:\Users\Kasper\Documents\WindowsPowerShell\Modules> git clone --recurse-submodules git@github.com:gaelcolas/log4ps.git
Cloning into 'log4ps'...
remote: Counting objects: 2707, done.
remote: Total 2707 (delta 0), reused 0 (delta 0), pack-reused 2707
Receiving objects: 100% (2707/2707), 6.42 MiB | 219.00 KiB/s, done.
Resolving deltas: 100% (2404/2404), done.
Checking connectivity... done.
Checking out files: 100% (2526/2526), done.
Submodule 'lib/lib.common' (https://github.com/gaelcolas/lib.common) registered for path 'lib/lib.common'
Cloning into 'lib/lib.common'...
remote: Counting objects: 49, done.
remote: Total 49 (delta 0), reused 0 (delta 0), pack-reused 49
Unpacking objects: 100% (49/49), done.
Checking connectivity... done.
Submodule path 'lib/lib.common': checked out '03c77de4e8a779138bd6dfbf12f4ca62693806b3'
C:\Users\Kasper\Documents\WindowsPowerShell\Modules> cd .\log4ps\
C:\Users\Kasper\Documents\WindowsPowerShell\Modules\log4ps [master ≡]> . .\examples\demo6.ps1
INFO - This test is killing puppies
This test is killing puppies
INFO - This is a verbose msg
DEBUG - Debug message
WARN - This is a WARN msg!
WARNING: This is a WARN msg!
ERROR - This is an error
Write-Error : This is an error
At C:\Users\Kasper\Documents\WindowsPowerShell\Modules\log4ps\examples\demo6.ps1:9 char:1
+ Write-Error 'This is an error'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Write-Error

Get-Content : Cannot find path 'C:\Users\Kasper\AppData\Local\Temp\example.log' because it does not exist.
At C:\Users\Kasper\Documents\WindowsPowerShell\Modules\log4ps\examples\demo6.ps1:11 char:1
+ Get-Content $env:TMP\example.log
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\Kasper...emp\example.log:String) [Get-Content], ItemNotFoundEx
   ception
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

INFO - C:\Users\Kasper\Documents\WindowsPowerShell\Modules\log4ps
C:\Users\Kasper\Documents\WindowsPowerShell\Modules\log4psINFO -  [
 [INFO - master
masterINFO -  =
 ≡INFO - ]
]>
kasperbrandenburg commented 8 years ago

This seems to conflict with postgit powershell module, and for some reason i couldn't get demo6 to work. I tried a new config, and it seems to work just fine.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
    </configSections>
    <log4net>
        <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fff[zzz]}   %logger [Line: %property{ScriptLineNumber}] %-5level - %message (%property{PSCallStack})%newline" />
            </layout>
        </appender>

        <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
            <file value="C:\Users\Kasper\Documents\WindowsPowerShell\Modules\log4ps\examples\myfile.log" />
            <appendToFile value="true" />
            <maximumFileSize value="100KB" />
            <maxSizeRollBackups value="2" />

            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fff[zzz]}   %logger [Line: %property{ScriptLineNumber}] %-5level - %message (%property{PSCallStack})%newline" />
            </layout>
        </appender>

        <root>
            <level value="DEBUG" />
            <appender-ref ref="ConsoleAppender" />
            <appender-ref ref="RollingFileAppender" />
        </root>
    </log4net>
</configuration>
gaelcolas commented 8 years ago

Hi, First of all, sorry for not replying to this before! The "output some type of array on all subsequent commands" is probably the default Log4net appender, which just log to the STDOUT (console) by default... not really useful but expected behaviour.

With regard to the error, if you meant Posh-git I don't have conflict, if you actually meant postgit I am not aware of this module.

I don't consider this module production-ready (it lacks serious tests, performance and I haven't had time to polish some angles), but by all mean do let me know feedback and I will try bringing it up to better quality (within a few months).

Thanks for trying it out!