> For the complete documentation index, see [llms.txt](https://support.powerio.com/hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.powerio.com/hub/faq/faq-en/hvac-codesys-faq/codesys-log-und-exception-log-sichern.md).

# Backing up the CODESYS log and exception log

This is how you back up the CODESYS log and the exception log of the OnException function after an exception via the Files tab in CODESYS.

After an exception, back up two files: the CODESYS log `codesyscontrol.log` and the exception log `codesysexception.log`. Both files are loaded into CODESYS via the tab **Files** onto the PC. The exception log is created only if the function `OnException` uses the relative path `codesysexception.log` .

Prerequisite: CODESYS is connected to the device.

## Download CODESYS log

1. Open the device in the device tree with a double-click and select the tab **Files**.
2. Click in the **Runtime System** on **Refresh**.
3. Select `codesyscontrol.log`. Also select `codesyscontrol_0.log`, `codesyscontrol_1.log` and `codesyscontrol_2.log`, if present.
4. Click on **<<**. CODESYS copies the files into the folder that is open in the **Host** area.

<figure><img src="https://3243479815-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYBzFv70TPLPkr2VWWUS%2Fuploads%2Fgit-blob-72256758608436eed4019701749b3f1022bcc4c2%2Fcodesys-log-dateien.png?alt=media" alt="Reiter Dateien in CODESYS mit markierter Datei codesyscontrol.log im Bereich Laufzeitsystem"><figcaption></figcaption></figure>

The runtime overwrites the oldest entries as soon as the log reaches about 4 MB. Therefore, back up the CODESYS log directly after an exception.

If `codesyscontrol.log` is missing, the log is located on the device in a place that CODESYS does not display. The cause and the solution are under [Where is the CODESYS log located on powerIO devices?](/hub/faq/faq-en/hvac-codesys-faq/wo-liegt-das-codesys-log.md).

## Set up exception log

The exception log writes a line with task and exception code for each exception. The CODESYS log does not contain an entry for the exception after an automatic restart.

1. Open **Task configuration** > **System events**. Check that the event **Exception** calls the function `OnExceptionWrapper` and is active.

<figure><img src="https://3243479815-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYBzFv70TPLPkr2VWWUS%2Fuploads%2Fgit-blob-2db953ffbf1e3a49a0f1a6d68bf022f733872c98%2Fcodesys-exception-systemereignisse.png?alt=media" alt="Reiter Systemereignisse der Taskkonfiguration mit dem aktiven Ereignis Exception und der Funktion OnExceptionWrapper"><figcaption></figcaption></figure>

2. Open in the view **POUs** calls the function `OnExceptionWrapper`. Check that the call `xLogExceptionToFile := TRUE` contains:

```iecst
OnException(EventPrm := EventPrm, xDebug := FALSE, xLogExceptionToFile := TRUE, xRestartRuntimeOnException := TRUE, tExceptionFunctionTimeout := T#45S);
```

3. Open the function `OnException`. Replace in `sExceptionLogPath` the path `/tmp/codesysexception.log` with `codesysexception.log`.

<figure><img src="https://3243479815-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYBzFv70TPLPkr2VWWUS%2Fuploads%2Fgit-blob-ce9c0daca7ae298de5cd52c1ef31db0f61fdb2ca%2Fcodesys-exception-pfad.png?alt=media" alt="Deklaration von sExceptionLogPath in OnException, oben mit dem alten Pfad /tmp/codesysexception.log, unten mit dem neuen Pfad codesysexception.log"><figcaption></figcaption></figure>

4. Upload the project to the device.

The runtime blocks paths outside the folder `PlcLogic`. With the old path, no file is therefore created, and the CODESYS log shows `Access denied to '/tmp/codesysexception.log' due to ForceIecFilePath`.

## Download exception log

1. Open in the tab **Files** in the area **Runtime System** the folder `PlcLogic`.
2. Select `codesysexception.log` and click on **<<**.

<figure><img src="https://3243479815-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYBzFv70TPLPkr2VWWUS%2Fuploads%2Fgit-blob-8408a4e6760c4bdf3a66bda7ab3b86fd1c1ab13b%2Fcodesys-exception-dateien-plclogic.png?alt=media" alt="Reiter Dateien in CODESYS mit markierter Datei codesysexception.log im Ordner PlcLogic"><figcaption></figcaption></figure>

Each exception results in one line:

<figure><img src="https://3243479815-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYBzFv70TPLPkr2VWWUS%2Fuploads%2Fgit-blob-4bc2e1d6bea7c7250d5fbc185646cd1b9d87fa4b%2Fcodesys-exception-log-zeile.png?alt=media" alt="Zeile im Exception Log mit Timestamp, App, Task MainTask, ExceptionCode 81, TaskInfo, Action und RunOn"><figcaption></figcaption></figure>

| Field           | Meaning                                                                             |
| --------------- | ----------------------------------------------------------------------------------- |
| `Timestamp`     | Time of the exception in milliseconds since 1 January 1970, already in local time   |
| `Task`          | Task in which the exception occurred                                                |
| `ExceptionCode` | Type of exception, for example `81` for a memory access violation                   |
| `Action`        | Reaction of the function, for example `TryExternalScript` for the automatic restart |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://support.powerio.com/hub/faq/faq-en/hvac-codesys-faq/codesys-log-und-exception-log-sichern.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
