Search code examples
nsis

unable to store the data in log file - NSIS


i want to add some data in the nsis log file, But when i ran the following command, it is getting executed but there is not data present in the log file.

Note : I already have the nsislog.dll file present in the plugin directory (x86-ansi & x86-unicode).

!include "MUI2.nsh"

XPStyle on

Section "Log test"

nsislog::log "c:\logfile.txt" "text to log"

SectionEnd


Solution

  • That plug-in only exists as ANSI, you can't just copy it to the Unicode plug-in directory and expect it to work. Luckily that plug-in is easily replaced with custom code:

    !include Util.nsh
    !define LogLine "!insertmacro WriteLineToFile"
    !macro WriteLineToFile file line
    Push `${line}`
    Push "${file}"
    !insertmacro CallArtificialFunction WriteLineToFileHelper
    !macroend
    !macro WriteLineToFileHelper
    Exch $0
    Exch
    Exch $1
    Push $2
    FileOpen $2 $0 a
    StrCmp $2 "" done
    FileSeek $2 0 END
    FileWrite $2 "$1$\r$\n"
    FileClose $2
    done:
    Pop $2
    Pop $1
    Pop $0
    !macroend
    
    
    Section 
    ${LogLine} "$INSTDIR\install.log" "Hello"
    ${LogLine} "$INSTDIR\install.log" "World"
    SectionEnd