sample code
コードはこんな感じで
open System.Diagnostics
/// Debugモードのときだけコンパイルする
#if DEBUG
/// リスナーをインスタンス化する
let listener = new DefaultTraceListener()
/// logファイルを指定する
let parentDic = System.Reflection.Assembly.GetEntryAssembly().Location |> fun x -> string ( System.IO.Directory.GetParent(x) )
listener.LogFileName <- System.IO.Path.Combine( parentDic, "log.txt" )
/// リスナーに追加する
Debug.Listeners.Add(listener)
#endif
let rec main s (acc:int)=
match s with
| "quit" -> () /// quitという文字列で終了する
| _ ->
/// stdoutから出力する
stdout.WriteLine(s)
/// log.txtに出力する
Debug.WriteLine(acc)
main (stdin.ReadLine()) (acc + 1)
[<EntryPointAttribute>]
let entry arg =
main arg.[0] 0
0
デバッグのしかた
まずdebugモードでコンパイル
$ fsharpc -d:DEBUG abc.fsx
で、ログファイルをリッスン
F
を押してForward forever
とする
$ less log.txt
実行してみる
$ mono abc.exe callmekohei
/// 標準出力へ
callmekohei
/// log.txtへ
0