Help us understand the problem. What is going on with this article?

ファイル名が日時のログ

現在時刻(OS準拠)を取得してログファイル名に

DateTime.Now.ToString("yyyy.MM.dd.HH.mm.ss") で西暦から秒まで取得できる.西暦など省略もできる.
System.Text.Encoding.GetEncoding("shift_jis"))でテキストのエンコード方式を指定できる.
下記の例ではexeのある階層に"yyyy.MM.dd.HH.mm.ss.log"の空ファイルができる.

        using TextWriter writerSync = TextWriter.Synchronized(new StreamWriter(DateTime.Now.ToString("yyyy.MM.dd.HH.mm.ss") + ".log", false, System.Text.Encoding.GetEncoding("shift_jis")));
        writerSync.WriteLine(DateTime.Now.ToString("HH.mm.ss:")+"ここにログを記述");

ログを7z(7zip)で圧縮する場合

階層内のログファイルをまとめて圧縮する.
ファイル名は"yyyy.MM.dd.HH.mm.ss.7z"になる.
以下のURLから"7z.exe"を入手しexeと同じ場所に配置する必要がある.
https://sevenzip.osdn.jp/download.html
-sdelは圧縮したら元のファイルを削除
-mx9は圧縮レベルで0は無圧縮(0-9)
".7zを".zipに変えるとzipになる

        ExecuteAnotherApp("7z.exe", "a " + DateTime.Now.ToString("yyyy.MM.dd.HH.mm.ss") + ".7z *.log -sdel -mx9", false, true);

        private void ExecuteAnotherApp(in string FileName, in string Arguments, bool UseShellExecute, bool CreateNoWindow) {
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo {
                FileName = FileName, Arguments = Arguments,
                UseShellExecute = UseShellExecute,
                CreateNoWindow = CreateNoWindow    // コンソール・ウィンドウを開かない
            }).WaitForExit();
        }
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away