Site cover image

Site icon imageIT Works Lab - blog

IT関連のメモ

[UiPath]ログ出力について① - ローカルでのログ出力

ローカルでのログファイル出力先について

  1. ロボットを実行した際に作成される実行ログファイル、その他、Studio実行時に出力されるログファイルについては、以下のパスに格納されます

 C:\Users\ユーザー名\AppData\Local\UiPath\Logs

  またはエクスプローラーで %localappdata%\UiPath\Logs を開きます。

ロボットの実行ログファイルは「yyyy-MM-dd_Execution.log」という名前で表示されます。
  上記以外のログファイルはUiPath Studio実行時に出力されるログとなります。

Image in a image block

  1. 上記ログフォルダはUiPath Studioで[デバッグ]タブ>[ログを開く]から開くことが可能です。

Image in a image block

<参考>

実行ログファイルの削除・ローテーションについて

  1. UiPath実行ログの削除・ローテーションについて

UiPathのローカルの実行ログは、デフォルトでは自動での削除・ローテーションなどが実施されず、蓄積され続ける形となります。

  1. ログファイル出力のカスタマイズ(削除・ローテーション)について

ロボットのログ出力は、UiPath Studioのインストールフォルダ内の NLog.config ファイルを編集することでカスタマイズできます。

◆サービスとしてインストールした場合

C:\Program Files\UiPath\Studio
◆ユーザー単位でインストールした場合
C:\Users\ユーザー名\AppData\Local\Programs\UiPath\Studio

  1. カスタマイズ方法

NLog.config の<target type="File"~>の箇所に以下を追加する

  archiveNumbering="Date"
  archiveEvery="Day"
  archiveDateFormat="yyyy-MM-dd"
  archiveFileName="${WorkflowLoggingDirectory}/{#}_Execution.log"
  maxArchiveFiles="10"
  
ログフォルダ配下保存するログファイル数は1 (当日のログファイルのみ)
それ以前のファイルは archivesフォルダへアーカイブ(退避)
archivesフォルダ内で保管するファイル数は10、それ以前のファイルは自動で削除される

NLog.config(デフォルト)

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <rules>
    <logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
  </rules>
  <targets>
    <target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${time} ${level} ${message}" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true" encoding="utf-8" writeBom="true" />
  </targets>
</nlog>

NLog.config(修正後)

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <rules>
    <logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
  </rules>
  <targets>
    <target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${time} ${level} ${message}" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true" encoding="utf-8" writeBom="true" archiveNumbering="Date" archiveEvery="Day" archiveDateFormat="yyyy-MM-dd" archiveFileName="${WorkflowLoggingDirectory}/archives/{#}_Execution.log" maxArchiveFiles="10" />
  </targets>
</nlog>

なお、Studio関連のログを制御する Studio.NLog.config についても同様に設定を実施

Studio.NLog.config(デフォルト)

<?xml version="1.0" encoding="utf-8"?>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <variable name="logDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <targets>
    <target name="AsyncTarget" xsi:type="AsyncWrapper">
      <target name="logfile" xsi:type="File" fileName="${logDirectory}/${shortdate}_${processname}.log" encoding="utf-8" writeBom="true" layout="${time} =&gt; [${level:uppercase=true}] [${logger}] [${threadid}] ${message}" />
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Warn" writeTo="AsyncTarget" />
  </rules>
</nlog>

Studio.NLog.config(修正後)

<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <variable name="logDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <targets>
    <target name="AsyncTarget" xsi:type="AsyncWrapper">
      <target name="logfile" xsi:type="File" fileName="${logDirectory}/${shortdate}_${processname}.log" encoding="utf-8" writeBom="true" layout="${time} =&gt; [${level:uppercase=true}] [${logger}] [${threadid}] ${message}" archiveNumbering="Date" archiveEvery="Day" archiveDateFormat="yyyy-MM-dd" archiveFileName="${WorkflowLoggingDirectory}/archives/{#}_${processname}.log" maxArchiveFiles="10" />
    </target>
  </targets>
  <rules>
    <logger name="*" minlevel="Warn" writeTo="AsyncTarget" />
  </rules>
</nlog>

Configの反映には、UiPathサービス(UiRobotSvc)の再起動が必要となります。

参考