I run CODESYS runtime as a service and use CmpLog (the LogAdd2 function) to log different events to a file. I have done this many times before on various projects and hardware, and it works fine.
On this particular system, I have CODESYS 3.5.20.40 running on a Windows 11 PC. The CODESYSControlService autostarts (with Local System credentials, the default), and the application runs fine. However, the configuration file is not read (or at least not the one that should be, or not the CmpLog section), and log files are not written to the disk.
I would be thankful if anyone knew why this is happening and how to fix it.
A note to CODESYS people: you must provide more information on the codesys configuration file, CODESYSControlService.exe and other major components and system behaviour. You created the service and various features (i.e. logging), but haven't explained how they work, which, in my opinion, is below standard for industrial automation software.
These are my observations:
- When running as a service, the config file is not read (none of them), or at least the CmpLog section is not read. I checked the log using Codesys IDE, and the CmpLog parameters are not the ones I have set in any of the config files. Which CmpLog config values does the service use, and where does it read them from? I have no idea, but it's not the config files. Here are the codesys config files I located on the PC's disk:
o C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\CODESYSControl.cfg (only 2 lines in this config)
o C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\AppDataFiles\CODESYSControlWinV3\CODESYSControl.cfg
o C:\Users\SRV\AppData\Roaming\CODESYS\CODESYSControlWinV3\C4DBB537\CODESYSControl.cfg
o C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\tempCFG\CODESYSControl.cfg
- When I run codesys as an app (e.g. by clicking the icon), this config file is read C:\Users\SRV\AppData\Roaming\CODESYS\CODESYSControlWinV3\C4DBB537\CODESYSControl.cfg and log files are written ok. The icon target is "C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\CODESYSControlService.exe" -d
o the -d option, I think, starts a cmd-like window showing service debug output (the output shown in log in the IDE)
o the -i option, again I think, means install the service
- I tried adding -d to service start parameters in the registry, but it started only once and after that it refused to start. Knowing what -d does and which other options are available would be great (e.g. can I make the service read a different config file).
- Syslog UDP logging works fine in any case.
- These are my CmpLog parameters
~~~ [CmpLog]
Logger.0.Name=PlcLog3
Logger.0.Filter=0xFFFFFFFF
Logger.0.Enable=1
Logger.0.MaxEntries=10003
Logger.0.MaxFileSize=50003
Logger.0.MaxFiles=33
Logger.0.Backend.0.ClassId=0x0000010B ;sends logger messages to SysOut
Logger.0.Backend.1.ClassId=0x00000104 ;writes logger messages in a file
Logger.0.Backend.2.ClassId=0x00000135 ;sends logger messages as UDP syslog
Logger.0.Type=0x314 ;Set the timestamp to RTC
~~~
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you sure when running as service, it is not reading configuration from
C:\Windows\System32\config\systemprofile\AppData\Roaming\CODESYS... ? Is the SRV user is set for the CODESYS services?
2 ways to fix it:
Change the CODESYSControl.cfg in the installation directory (ProgramFiles/CODESYS...). Replace %APPDATA% with something fix.
Modify the service configuration in windows service manager to run as a different user (ie bot as Local system account)
π
1
Last edit: Strucc.c 2025-02-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I run CODESYS runtime as a service and use CmpLog (the LogAdd2 function) to log different events to a file. I have done this many times before on various projects and hardware, and it works fine.
On this particular system, I have CODESYS 3.5.20.40 running on a Windows 11 PC. The CODESYSControlService autostarts (with Local System credentials, the default), and the application runs fine. However, the configuration file is not read (or at least not the one that should be, or not the CmpLog section), and log files are not written to the disk.
I would be thankful if anyone knew why this is happening and how to fix it.
A note to CODESYS people: you must provide more information on the codesys configuration file, CODESYSControlService.exe and other major components and system behaviour. You created the service and various features (i.e. logging), but haven't explained how they work, which, in my opinion, is below standard for industrial automation software.
These are my observations:
- When running as a service, the config file is not read (none of them), or at least the CmpLog section is not read. I checked the log using Codesys IDE, and the CmpLog parameters are not the ones I have set in any of the config files. Which CmpLog config values does the service use, and where does it read them from? I have no idea, but it's not the config files. Here are the codesys config files I located on the PC's disk:
o C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\CODESYSControl.cfg (only 2 lines in this config)
o C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\AppDataFiles\CODESYSControlWinV3\CODESYSControl.cfg
o C:\Users\SRV\AppData\Roaming\CODESYS\CODESYSControlWinV3\C4DBB537\CODESYSControl.cfg
o C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\tempCFG\CODESYSControl.cfg
- When I run codesys as an app (e.g. by clicking the icon), this config file is read C:\Users\SRV\AppData\Roaming\CODESYS\CODESYSControlWinV3\C4DBB537\CODESYSControl.cfg and log files are written ok. The icon target is "C:\Program Files (x86)\CODESYS 3.5.20.40\GatewayPLC\CODESYSControlService.exe" -d
o the -d option, I think, starts a cmd-like window showing service debug output (the output shown in log in the IDE)
o the -i option, again I think, means install the service
- I tried adding -d to service start parameters in the registry, but it started only once and after that it refused to start. Knowing what -d does and which other options are available would be great (e.g. can I make the service read a different config file).
- Syslog UDP logging works fine in any case.
- These are my CmpLog parameters
~~~
[CmpLog]
Logger.0.Name=PlcLog3
Logger.0.Filter=0xFFFFFFFF
Logger.0.Enable=1
Logger.0.MaxEntries=10003
Logger.0.MaxFileSize=50003
Logger.0.MaxFiles=33
Logger.0.Backend.0.ClassId=0x0000010B ;sends logger messages to SysOut
Logger.0.Backend.1.ClassId=0x00000104 ;writes logger messages in a file
Logger.0.Backend.2.ClassId=0x00000135 ;sends logger messages as UDP syslog
Logger.0.Type=0x314 ;Set the timestamp to RTC
~~~
Are you sure when running as service, it is not reading configuration from
C:\Windows\System32\config\systemprofile\AppData\Roaming\CODESYS... ? Is the SRV user is set for the CODESYS services?
2 ways to fix it:
Last edit: Strucc.c 2025-02-28
Wow! Thanks mr Strucc.
Changed to service to run as local acc, and now log works!
The service (run from local acc) is using this config: C:\Users\SRV\AppData\Roaming\CODESYS\CODESYSControlWinV3\C4DBB537\CODESYSControl.cfg
The path you first mentioned (c:\Windows\System32\config\systemprofile\AppData\Roaming) has no CODESYS folder in it (Windows 11 24H2 b26100.3194).
Thanks for your help :)