windows-serviceswindows-server-2012-r2nxlog

Nxlog cannot collect logs in certain directories


Background

Use nxlog to collect the logs of win server 2012 R2 server. The configuration file is as follows

define ROOT     C:\Program Files (x86)\nxlog
define CERTDIR  %ROOT%\cert
define CONFDIR  %ROOT%\conf
define LOGDIR   %ROOT%\data
define LOGFILE  %LOGDIR%\nxlog.log
LogFile %LOGFILE%

Moduledir %ROOT%\modules
CacheDir  %ROOT%\data
Pidfile   %ROOT%\data\nxlog.pid
SpoolDir  %ROOT%\data

<Extension _syslog>
    Module      xm_syslog
</Extension>

<Input in1>
    Module      im_file
    ReadFromLast true      
    SavePos     false      
    File     "C:\\中文\log.log"
</Input>

<Output out>
    Module      om_udp
    Host        192.168.40.3
    Port        514
</Output>

<Route 1>
    Path        in1 => out
</Route>

Process

If we use background code, we will get error. Check the log of nxlog on the server and found the following error

2020-11-26 10:13:02 ERROR failed to open C:\中文\log.log; Invalid argument
2020-11-26 10:13:04 ERROR apr_stat failed on file C:\中文\log.log; Invalid argument

But if we just use English string directory. Everything will be ok. Such as

define ROOT     C:\Program Files (x86)\nxlog
define CERTDIR  %ROOT%\cert
define CONFDIR  %ROOT%\conf
define LOGDIR   %ROOT%\data
define LOGFILE  %LOGDIR%\nxlog.log
LogFile %LOGFILE%

Moduledir %ROOT%\modules
CacheDir  %ROOT%\data
Pidfile   %ROOT%\data\nxlog.pid
SpoolDir  %ROOT%\data

<Extension _syslog>
    Module      xm_syslog
</Extension>

<Input in1>
    Module      im_file
    ReadFromLast true      
    SavePos     false      
    File     "C:\\log.log"
</Input>

<Output out>
    Module      om_udp
    Host        192.168.40.3
    Port        514
</Output>

<Route 1>
    Path        in1 => out
</Route>

Problem

How to make nxlog collect logs in not english string directory?

OT


Solution

  • Ensure that the conf file code is UTF-8 enter image description here