| 56 | |
| 57 | template<typename Mutex> |
| 58 | void lazy_file_sink<Mutex>::open() |
| 59 | { |
| 60 | if (!std::exchange(m_Tried, true)) |
| 61 | { |
| 62 | std::error_code err; |
| 63 | std::filesystem::create_directories(m_File.parent_path(), err); |
| 64 | if (!err) |
| 65 | { |
| 66 | m_Handle.reset(CreateFile(m_File.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, nullptr)); |
| 67 | if (m_Handle) |
| 68 | { |
| 69 | write(UTF8_BOM); |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | LastErrorHandle(spdlog::level::err, L"Failed to create log file. Logs won't be available during this session."); |
| 74 | } |
| 75 | } |
| 76 | else |
| 77 | { |
| 78 | StdErrorCodeHandle(err, spdlog::level::err, L"Failed to create log directory. Logs won't be available during this session."); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | template<typename Mutex> |
| 84 | template<typename T> |