在 SMath Studio 中启用日志记录
当您在 SMath Studio 中遇到问题或异常行为时,启用内置日志记录有助于诊断问题。日志文件会记录详细的跟踪信息,您(或您的软件供应商)可以借此定位问题的根本原因。
前提条件¶
请先确认 SMath Studio 的安装位置:
- 按机器安装: C:\Program Files (x86)\SMath\(或类似路径)
- 按用户安装: 您的用户配置文件夹(例如 C:\Users\<您的用户名>...)
启用日志记录¶
- 关闭所有正在运行的 SMath Studio 实例。在编辑配置文件之前,请确保所有 SMath Studio 进程均已关闭。
- 进入 SMath Studio 的安装文件夹,使用文本编辑器(例如记事本)打开文件 Solver.exe.config。注意: 如果 SMath Studio 是按机器安装的,修改此文件可能需要管理员权限。请右键点击文本编辑器,选择以管理员身份运行。
-
取消注释日志记录相关的代码块。该文件默认包含两个被注释掉的代码块。您需要删除 XML 注释标记(
<!--和-->),使配置生效。以下是默认(已注释)的内容 ——
<source>元素和<add>监听器元素均包裹在注释中:<?xml version="1.0" encoding="utf-8"?> <configuration> <system.diagnostics> <sources> <!-- The name attribute of <source> element is split by dot in order to build the hierarchy of sources for loggers. The source with name="root" defines the root in the hierarchy. Use attribute newSwitch="true" in order to redefine the switch for the related source and its descendants. Use attribute newListeners="true" in order to redefine the listeners for the related source and its descendants. Supported values of attribute switchValue in order of verbosity: "Off" (default), "Critical", "Error", "Warning", "Information", "Verbose" --> <!-- <source name="root"> <listeners> <add name="file" /> </listeners> </source> <source name="SMath.Controls" newSwitch="true" switchValue="Error" /> <source name="SMath.Environment" newSwitch="true" switchValue="Error" /> <source name="SMath.Document" newSwitch="true" switchValue="Error" /> <source name="SMath.Manager" newSwitch="true" switchValue="Error" /> <source name="SMath.UI" newSwitch="true" switchValue="Error" /> --> </sources> <sharedListeners> <!-- Writes trace to file --> <!-- <add name="file" type="SMath.Manager.Logging.FileTraceListener, SMath.Manager" traceOutputOptions="DateTime,ProcessId,ThreadId" initializeData="%APPDATA%\SMath\Solver.log"/> --> </sharedListeners> <trace autoflush="true" indentsize="4" /> </system.diagnostics> </configuration>请取消注释包含实际配置的两个 XML 代码块(
<source>元素和<add>监听器元素),同时保留说明性注释(包含解释性文字的第一段注释)。取消注释后,文件内容应如下所示:<?xml version="1.0" encoding="utf-8"?> <configuration> <system.diagnostics> <sources> <!-- The name attribute of <source> element is split by dot in order to build the hierarchy of sources for loggers. The source with name="root" defines the root in the hierarchy. Use attribute newSwitch="true" in order to redefine the switch for the related source and its descendants. Use attribute newListeners="true" in order to redefine the listeners for the related source and its descendants. Supported values of attribute switchValue in order of verbosity: "Off" (default), "Critical", "Error", "Warning", "Information", "Verbose" --> <source name="root"> <listeners> <add name="file" /> </listeners> </source> <source name="SMath.Controls" newSwitch="true" switchValue="Error" /> <source name="SMath.Environment" newSwitch="true" switchValue="Error" /> <source name="SMath.Document" newSwitch="true" switchValue="Error" /> <source name="SMath.Manager" newSwitch="true" switchValue="Error" /> <source name="SMath.UI" newSwitch="true" switchValue="Error" /> </sources> <sharedListeners> <!-- Writes trace to file --> <add name="file" type="SMath.Manager.Logging.FileTraceListener, SMath.Manager" traceOutputOptions="DateTime,ProcessId,ThreadId" initializeData="%APPDATA%\SMath\Solver.log"/> </sharedListeners> <trace autoflush="true" indentsize="4" /> </system.diagnostics> </configuration>提示: 只需取消注释包含嵌套 XML 结构的元素(
<source>和<add>元素),纯说明性文字应继续保留在注释中。 -
保存修改后的 Solver.exe.config 文件并关闭文本编辑器。
- 打开 SMath Studio,重复执行引发问题的操作步骤。此时应用程序会开始将跟踪输出写入日志文件。
- 获取日志文件。进入日志文件夹(无需管理员权限):%APPDATA%\SMath\(按 Win+R,输入该路径后按 Enter 即可快速打开)。日志文件名为 Solver.log。
- 查看日志。用文本编辑器打开 Solver.log,滚动到文件末尾 —— 最新的记录通常就是与问题相关的内容所在之处。您可以自行定位错误/异常信息,或将日志文件(或其相关部分)附加到发给软件供应商的支持请求中。
关闭日志记录¶
问题解决或日志已提交分享后,建议将日志记录重新关闭:
- 关闭 SMath Studio。
- 在 Solver.exe.config 中重新为两个 XML 代码块加上注释(恢复为上文所示的原始状态)。
- 保存文件。
- 如需清理,可选择删除 %APPDATA%\SMath\Solver.log。
注意: 如果一直保持日志记录开启状态,Solver.log 文件会随着时间不断增长,占用磁盘空间,并可能拖慢文件操作速度。诊断完成后,建议恢复为默认(已注释)状态,这是最佳实践。