lundi 24 septembre 2018

Trying to write in text file but every time it overwrites

below is my func:

void Logger_class::LOG_Write(string Source, string Msg)
{
    Poco::Path Ppath;
    bool Param = getApplicationPath(Ppath);
    Poco::Path parent(Ppath.parent());
    FilePath = parent.toString();

    Poco::DateTime now;
    Poco::FileOutputStream fos;
    std::string CurrentDate = DateTimeFormatter::format(now, "%Y%m%d");
    FileName = CurrentDate + "data" + ".txt";

    Poco::File file(FilePath + FileName);
    if (!file.exists() || !file.canRead())
    {
        Poco::FileOutputStream fos(FilePath + FileName, std::ios::binary);
        fos << "Sys Logging has been initiated...\n";
    }

    fos.open(FilePath + FileName, std::ios::binary || std::ios::app);
    fos << Msg << std::endl;
    fos.close();

}

Calling this func from main by:

log_obj.LOG_Write("ASX", "Test Success message");
log_obj.LOG_Write("ASX", "Test Error message");

Outpot of the file is: Test Error messageeinitiated...

It starts from 1st line of file to write messages and deletes existing data. How can i point to new line? Thanks

Aucun commentaire:

Enregistrer un commentaire