0

has anyone tried to use a log4j.xml reference within a WinRun4j service configuration. here is a copy of my service.ini file. I have tried many configuration combinations. this is just my latest attempt

service.class=org.boris.winrun4j.MainService
service.id=SimpleBacnetIpDataTransfer
service.name=Simple Backnet IP DataTransfer Service
service.description=This is the service for the Simple Backnet IP DataTransfer.
service.startup=auto

classpath.1=C:\Inbox\DataTransferClient-1.0-SNAPSHOT-jar-with-dependencies.jar
classpath.2=WinRun4J.jar
classpath.3=C:\Inbox\log4j-1.2.16.jar

arg.1=C:\Inbox\DataTransferClient.xml

log=C:\WinRun4J-Service\SimpleBacnetIpDataTransfer\NBP-DT-service.log
log.overwrite=true
log.roll.size=10MB

[MainService]
class=com.shiftenergy.ws.App

vmarg.1=-Xdebug
vmarg.2=-Xnoagent
vmarg.3=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
vmarg.4=-Dlog4j.configuration=file:C:\Inbox\log4j.xml

within the log4j.xml file, there is reference to a log file for when the application runs. if I run the java -jar -Dlog4j.configuration=file:C:\Inbox\log4j.xml ...., the log file is created accordingly. if I register my service and start the service, the log file does not get created.

has anyone had success using the -D log4j configuration, using winrun4j?

thanks

3 Answers3

1

I think that you provided the vmarg.4 parameter incorrectly. In your case it has to be like:

vmarg.4=-Dlog4j.configurationFile=[Path for log4j.xml]

I am also using the same and in my case, it is working perfectly fine. Please see below example:

vmarg.1=-Dlog4j.configurationFile=.\log4j2.xml

Jay
  • 111
  • 1
  • 4
  • 13
0

Have you tried setting the path in your code instead:

System.setProperty("log4j.configurationFile", "config/log4j.xml");

I'm using a relative path to a folder named config that contains log4j.xml. An absolute path is not recommended, but may work as well.

Just be sure to set this before making any calls to log4j, including any log4j config settings or static method calls!

    System.setProperty("log4j.configurationFile", "config/log4j.xml");
    final Logger log = Logger.getLogger(Main.class);
    log.info("Starting up");
Scott Wardlaw
  • 652
  • 1
  • 8
  • 13
0

I didn't specify the log4j path in the ini file, only placed log4j.xml file at the same place the jar was placed.

Also without specify the

System.setProperty("log4j.configurationFile", "config/log4j.xml");

In the Java project it was stored in (src/main/resources) and will be included in the jar, but it will not be that one used if placed outside the jar.

Andreas Mattisson
  • 1,051
  • 2
  • 19
  • 39