AX2012 向TXT文件写数据

public static void saveLog(str     _msg)
{
    TextIo              textIo;
    Filename            name;
    System.DateTime     time;
    str                 timeStr;
    FileIOPermission    fioPermission;
    #File
    ;

    time = System.DateTime::get_Now();
    timeStr = time.ToString("yyyy-MM-dd HH-mm-ss");
    name = strFmt(@"%1\log\log %2.txt", parameter.FilePathStr, timeStr);

    fioPermission = new FileIOPermission(name, "RW");
    fioPermission.assert();

    //检查是否存在log文件夹,如果不存在,则创建
    if (!isRunningOnServer() && !WinApi::pathExists(parameter.FilePathStr + "\\log"))
    {
        System.IO.Directory::CreateDirectory(parameter.FilePathStr + "\\log"); //创建该文件夹
    }

    textIo = new TextIo(name, #IO_WRITE);
    textIo.write(_msg);
    textIo = null;
    CodeAccessPermission::revertAssert();
}

 

posted @ 2020-12-01 11:07  一口一个小馒头  阅读(107)  评论(0编辑  收藏  举报