Repository: microsoft/VbsEnclaveTooling
Pull request #91: Allow user to write logs into their chosen dir, default to cwd
Author: login: SohamDas2021
Created: 2025-05-21T22:08:05Z | Merged: 2025-05-23T21:20:21Z

This PR extends the logging subsystem to allow specifying a custom output directory (defaulting to the current working directory) and updates sample apps and documentation to match.
•	Added an optional logDirectory parameter to the logger constructor, defaulting to std::filesystem::current_path()
•	Updated sample applications to use .wstring() instead of .c_str() for std::filesystem::path
•	Revised README to reflect that telemetry files are now stored in the current working directory


Diff:
diff --git a/SampleApps/SampleApps/README.md b/SampleApps/SampleApps/README.md
index e2e96263..189d2d97 100644
--- a/SampleApps/SampleApps/README.md
+++ b/SampleApps/SampleApps/README.md
@@ -70,4 +70,4 @@ https://learn.microsoft.com/windows/win32/trusted-execution/vbs-enclaves-dev-gui
 
 	- We support telemetry strings from the Enclave that are 2048 chars or shorter. Refer to telemetry usage in the 
 sample app.
-	- Telemetry files are stored in c:\VeilLogs.	
+	- Telemetry files are stored in user specified dir or the current working directory (by default).	
diff --git a/SampleApps/SampleApps/SampleApp1/main.cpp b/SampleApps/SampleApps/SampleApp1/main.cpp
index 7ec26be3..39766260 100644
--- a/SampleApps/SampleApps/SampleApp1/main.cpp
+++ b/SampleApps/SampleApps/SampleApp1/main.cpp
@@ -279,10 +279,10 @@ int mainEncryptDecrpyt(uint32_t activityLevel)
 {
     int choice;
     std::wstring input;
-    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().c_str();;
-    const std::wstring encryptedDataDirPath = std::filesystem::current_path().c_str();
+    const std::wstring encryptedKeyDirPath = std::filesystem::current_path().wstring();
+    const std::wstring encryptedDataDirPath = std::filesystem::current_path().wstring();
     std::wstring encryptedInputFilePath = encryptedDataDirPath + L"\\encrypted";
-    std::wstring tagFilePath = encrytedKeyDirPath + L"\\tag";
+    std::wstring tagFilePath = encryptedKeyDirPath + L"\\tag";
     bool programExecuted = false;
 
     veil::vtl0::logger::logger veilLog(
@@ -309,7 +309,7 @@ int mainEncryptDecrpyt(uint32_t activityLevel)
     constexpr PCWSTR keyMoniker = L"MyEncryptionKey-001";
 
     // File with secured encryption key bytes
-    auto keyFilePath = std::filesystem::path(encrytedKeyDirPath) / keyMoniker;
+    auto keyFilePath = std::filesystem::path(encryptedKeyDirPath) / keyMoniker;
 
     do
     {
@@ -418,10 +418,10 @@ int mainEncryptDecrpytThreadpool(uint32_t activityLevel)
 
     int choice;
     std::wstring input1, input2;
-    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().c_str();
-    const std::wstring encryptedDataDirPath = std::filesystem::current_path().c_str();
+    const std::wstring encryptedKeyDirPath = std::filesystem::current_path().wstring();
+    const std::wstring encryptedDataDirPath = std::filesystem::current_path().wstring();
     std::wstring encryptedInputFilePath = encryptedDataDirPath + L"\\encrypted";
-    std::wstring tagFilePath = encrytedKeyDirPath + L"\\tag";
+    std::wstring tagFilePath = encryptedKeyDirPath + L"\\tag";
     bool programExecuted = false;
 
     veil::vtl0::logger::logger veilLog(
@@ -433,7 +433,7 @@ int mainEncryptDecrpytThreadpool(uint32_t activityLevel)
     constexpr PCWSTR keyMoniker = L"MyEncryptionKey-001";
 
     // File with secured encryption key bytes
-    auto keyFilePath = std::filesystem::path(encrytedKeyDirPath) / keyMoniker;
+    auto keyFilePath = std::filesystem::path(encryptedKeyDirPath) / keyMoniker;
 
     do
     {
diff --git a/SampleApps/SampleApps/SampleApps.sln b/SampleApps/SampleApps/SampleApps.sln
index bdecae43..80f04624 100644
--- a/SampleApps/SampleApps/SampleApps.sln
+++ b/SampleApps/SampleApps/SampleApps.sln
@@ -51,4 +51,7 @@ Global
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {2CC90DE8-BC52-49A9-9902-2F8382149CFC}
 	EndGlobalSection
+	GlobalSection(SharedMSBuildProjectFiles) = preSolution
+		packages\Microsoft.Windows.VbsEnclaveTooling.0.0.0\src\VbsEnclaveSDK\veil_any_inc\veil_any_inc.vcxitems*{d2c762e2-0de1-4f72-98c9-75f7bd69d17e}*SharedItemsImports = 4
+	EndGlobalSection
 EndGlobal
diff --git a/SampleApps/SampleApps/SampleEnclave/my_exports.cpp b/SampleApps/SampleApps/SampleEnclave/my_exports.cpp
index d0e7fca9..d22373a4 100644
--- a/SampleApps/SampleApps/SampleEnclave/my_exports.cpp
+++ b/SampleApps/SampleApps/SampleEnclave/my_exports.cpp
@@ -292,7 +292,7 @@ HRESULT VbsEnclave::VTL1_Declarations::RunEncryptionKeyExample_CreateEncryptionK
     
     auto activityLevel = (veil::any::logger::eventLevel)activity_level;
 
-    veil::vtl1::logger::implementation::add_log_from_enclave(
+    veil::vtl1::logger::add_log_from_enclave(
         L"[Enclave] In RunEncryptionKeyExample_CreateEncryptionKeyImpl", 
         veil::any::logger::eventLevel::EVENT_LEVEL_CRITICAL,
         activityLevel,
@@ -301,7 +301,7 @@ HRESULT VbsEnclave::VTL1_Declarations::RunEncryptionKeyExample_CreateEncryptionK
     debug_print("");
     debug_print(L"[Create flow]");
     debug_print("");
-    veil::vtl1::logger::implementation::add_log_from_enclave(
+    veil::vtl1::logger::add_log_from_enclave(
         L"[Enclave] Create flow", 
         veil::any::logger::eventLevel::EVENT_LEVEL_VERBOSE,
         activityLevel,
@@ -311,7 +311,7 @@ HRESULT VbsEnclave::VTL1_Declarations::RunEncryptionKeyExample_CreateEncryptionK
 
     // Generate our encryption key
     debug_print(L"1. Generating our encryption key");
-    veil::vtl1::logger::implementation::add_log_from_enclave(
+    veil::vtl1::logger::add_log_from_enclave(
         L"[Enclave] Generating our encryption key",
         veil::any::logger::eventLevel::EVENT_LEVEL_INFO,
         activityLevel,
@@ -319,7 +319,7 @@ HRESULT VbsEnclave::VTL1_Declarations::RunEncryptionKeyExample_CreateEncryptionK
     auto encryptionKeyBytes = veil::vtl1::crypto::generate_symmetric_key_bytes();
     debug_print(L" ...CHECKPOINT: encryption key byte count: %d", encryptionKeyBytes.size());
     std::wstring logSizeStr = std::to_wstring(encryptionKeyBytes.size());
-    veil::vtl1::logger::implementation::add_log_from_enclave(
+    veil::vtl1::logger::add_log_from_enclave(
         L"[Enclave] Encryption key byte count: " + logSizeStr,
         veil::any::logger::eventLevel::EVENT_LEVEL_CRITICAL,
         activityLevel,
@@ -328,7 +328,7 @@ HRESULT VbsEnclave::VTL1_Declarations::RunEncryptionKeyExample_CreateEncryptionK
     
     // Seal it so only our enclave may open it
     debug_print(L"4. Sealing the serialized key material for our enclave only");
-    veil::vtl1::logger::implementation::add_log_from_enclave(
+    veil::vtl1::logger::add_log_from_enclave(
         L"[Enclave] Sealing the serialized key material for our enclave only",
         veil::any::logger::eventLevel::EVENT_LEVEL_INFO,
         activityLevel,
@@ -336,7 +336,7 @@ HRESULT VbsEnclave::VTL1_Declarations::RunEncryptionKeyExample_CreateEncryptionK
     auto sealedKeyMaterial = veil::vtl1::crypto::seal_data(encryptionKeyBytes, ENCLAVE_IDENTITY_POLICY_SEAL_SAME_IMAGE, ENCLAVE_RUNTIME_POLICY_ALLOW_FULL_DEBUG);
     debug_print(L" ...CHECKPOINT: sealed key material byte count: %d", sealedKeyMaterial.size());
     logSizeStr = std::to_wstring(sealedKeyMaterial.size());
-    veil::vtl1::logger::implementation::add_log_from_enclave(
+    veil::vtl1::logger::add_log_from_enclave(
         L"[Enclave] Sealed key material byte count: " + logSizeStr,
         veil::any::logger::eventLevel::EVENT_LEVEL_CRITICAL,
         activityLevel,
@@ -372,7 +372,7 @@ HRESULT RunEncryptionKeyExample_LoadEncryptionKeyImpl(
 
     auto activityLevel = (veil::any::logger::eventLevel)activity_level;
 
-    veil::vtl1::logger::implementation::add_log_from_enclave(
+    veil::vtl1::logger::add_log_from_enclave(
         L"[Enclave] In RunEncryptionKeyExample_LoadEncryptionKeyImpl",
         veil::any::logger::eventLevel::EVENT_LEVEL_CRITICAL,
         activityLevel,
diff --git a/src/VbsEnclaveSDK/src/veil_enclave_lib/logger.vtl1.h b/src/VbsEnclaveSDK/src/veil_enclave_lib/logger.vtl1.h
index e71d0a40..250b9152 100644
--- a/src/VbsEnclaveSDK/src/veil_enclave_lib/logger.vtl1.h
+++ b/src/VbsEnclaveSDK/src/veil_enclave_lib/logger.vtl1.h
@@ -15,18 +15,18 @@ namespace veil::vtl1::logger
         {
             void add_log(std::wstring_view log, std::wstring_view logFilePath);
         }
+    }
 
-        inline void add_log_from_enclave(
+    inline void add_log_from_enclave(
             std::wstring_view log,
             veil::any::logger::eventLevel logLevel,
             veil::any::logger::eventLevel runtimeLogLevel,
             std::wstring_view logFilePath)
-        {
+    {
 
-            if ((int)logLevel <= (int)runtimeLogLevel)
-            {
-                implementation::callouts::add_log(log, logFilePath);
-            }
+        if ((int)logLevel <= (int)runtimeLogLevel)
+        {
+            implementation::callouts::add_log(log, logFilePath);
         }
     }
 }
diff --git a/src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h b/src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
index 9e6046b9..f39c579d 100644
--- a/src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
+++ b/src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
@@ -12,11 +12,6 @@
 
 #include "..\veil_any_inc\logger.any.h"
 
-namespace veil::vtl0::implementation::callbacks
-{
-    void* add_log(void* args) noexcept;
-}
-
 namespace veil::vtl0
 {
     namespace logger
@@ -49,11 +44,6 @@ namespace veil::vtl0
                 return modified;
             }
 
-            void SetLogFilePath()
-            {
-                logFilePath = L"c:\\VeilLogs\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
-            }
-
             static std::wstring CreateTimestamp()
             {
                 // Get the current time
@@ -96,10 +86,19 @@ namespace veil::vtl0
 
             public:
             logger(const std::wstring& providerName,
-                const std::wstring& guidStr,
-                const veil::any::logger::eventLevel level) : provider(providerName), guid(guidStr), logLevel(level)
+               const std::wstring& guidStr,
+               const veil::any::logger::eventLevel level,
+               const std::filesystem::path& logDirectory = std::filesystem::path()) : provider(providerName), guid(guidStr), logLevel(level)
             {
-                SetLogFilePath();
+               if (!logDirectory.empty())
+               {
+                   logFilePath = logDirectory.wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
+               }
+               else
+               {
+                   // Default to the current working directory if no directory is provided
+                   logFilePath = std::filesystem::current_path().wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
+               }
             }
 
             void AddTimestampedLog(const std::wstring& log, const veil::any::logger::eventLevel level) // Called from Host


Reviews:
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR updates the logging functionality to write log files to the current working directory instead of a hard-coded path.  
- In logger.vtl0.h, the log file path is now constructed using the current working directory.  
- In main.cpp, an extra semicolon was removed and a variable naming inconsistency was identified.  
- In README.md, the telemetry storage location description was updated.

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

| File                                                      | Description                                                             |
| --------------------------------------------------------- | ----------------------------------------------------------------------- |
| src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h          | Updated log file path to use the current working directory.             |
| SampleApps/SampleApps/SampleApp1/main.cpp                 | Fixed an extra semicolon and noted a naming issue in the variable.      |
| SampleApps/SampleApps/README.md                           | Revised documentation to reflect the new log file storage location.     |


<details>
<summary>Comments suppressed due to low confidence (2)</summary>

**src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:54**
* Consider using std::filesystem::path for constructing file paths (e.g., using the / operator) instead of manual string concatenation for improved portability and clarity.
```
logFilePath = std::filesystem::current_path().wstring() + L"\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
```
**SampleApps/SampleApps/SampleApp1/main.cpp:281**
* The variable name 'encrytedKeyDirPath' appears to be misspelled; consider renaming it to 'encryptedKeyDirPath' for clarity.
```
const std::wstring encrytedKeyDirPath = std::filesystem::current_path().c_str();;
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-21T22:09:08Z
user: login: jsidewhite
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-21T22:11:50Z
user: login: jsidewhite
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-21T22:18:28Z
user: login: jsidewhite
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-21T22:43:13Z
user: login: SohamDas2021
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-21T22:51:55Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This PR extends the logging subsystem to allow specifying a custom output directory (defaulting to the current working directory) and updates sample apps and documentation to match.

- Added an optional `logDirectory` parameter to the logger constructor, defaulting to `std::filesystem::current_path()`
- Updated sample applications to use `.wstring()` instead of `.c_str()` for `std::filesystem::path`
- Revised README to reflect that telemetry files are now stored in the current working directory

### Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

| File                                                        | Description                                                       |
| ----------------------------------------------------------- | ----------------------------------------------------------------- |
| src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h           | Added `logDirectory` parameter and logic for defaulting to cwd    |
| SampleApps/SampleApps/SampleApp1/main.cpp                   | Switched from `.c_str()` to `.wstring()` and fixed path handling |
| SampleApps/SampleApps/README.md                             | Updated documentation to state telemetry files are in cwd         |


<details>
<summary>Comments suppressed due to low confidence (1)</summary>

**src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:91**
* The new `logDirectory` parameter and the default-to-cwd behavior introduce additional code paths. Consider adding unit tests to verify both custom directory logging and default directory fallback.
```
logger(const std::wstring& providerName, const std::wstring& guidStr, const veil::any::logger::eventLevel level, const std::filesystem::path& logDirectory = std::filesystem::path())
```
</details>


state: COMMENTED
author_association: NONE
submitted_at: 2025-05-21T23:06:43Z
user: login: jsidewhite
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-23T20:58:09Z
user: login: jsidewhite
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-05-23T20:58:39Z
user: login: jsidewhite
body: :shipit:
state: APPROVED
author_association: MEMBER
submitted_at: 2025-05-23T21:10:35Z

Review comments:
diff_hunk: @@ -279,7 +279,7 @@ int mainEncryptDecrpyt(uint32_t activityLevel)
 {
     int choice;
     std::wstring input;
-    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().c_str();;
+    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().c_str();
path: SampleApps/SampleApps/SampleApp1/main.cpp
user: login: jsidewhite
body: >.c_str(); [](http://example.com/codeflow?start=75&length=9)

since you're already here, should be .wstring(); #Resolved
created_at: 2025-05-21T22:11:50Z
author_association: MEMBER
diff_hunk: @@ -49,9 +49,9 @@ namespace veil::vtl0
                 return modified;
             }
 
-            void SetLogFilePath()
-            {
-                logFilePath = L"c:\\VeilLogs\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
+            void SetLogFilePath()  
+            {  
+               logFilePath = std::filesystem::current_path().wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";  
path: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
user: login: jsidewhite
body: >std::filesystem::current_path() [](http://example.com/codeflow?start=29&length=31)

so, the problem here is that this could now throw an exception depending on where the program is run from, whereas before it deterministically required admin to write to c:\veillog

(what if the user launches from a tile, what is the CWD? c:\program files? not even admin can write there)

if we're going to fix this anyway, then why not let the ctor take an argument that specifies the path? #Resolved
created_at: 2025-05-21T22:18:28Z
author_association: MEMBER
diff_hunk: @@ -49,9 +49,9 @@ namespace veil::vtl0
                 return modified;
             }
 
-            void SetLogFilePath()
-            {
-                logFilePath = L"c:\\VeilLogs\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
+            void SetLogFilePath()  
path: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
user: login: jsidewhite
body: >SetLogFilePath [](http://example.com/codeflow?start=17&length=14)

wait is this function even called?  it looks like logging from vtl1 is going through the static functions only #Closed
created_at: 2025-05-21T22:43:13Z
author_association: MEMBER
diff_hunk: @@ -49,9 +49,9 @@ namespace veil::vtl0
                 return modified;
             }
 
-            void SetLogFilePath()
-            {
-                logFilePath = L"c:\\VeilLogs\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
+            void SetLogFilePath()  
path: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
user: login: SohamDas2021
body: Yes, it is. The logger class is constructed in vtl0 and used for host app logs. We use the static function add_log_from_enclave to log from the enclave. We pass the remaining logger params into the enclave. 
created_at: 2025-05-21T22:51:55Z
author_association: COLLABORATOR
diff_hunk: @@ -279,8 +279,8 @@ int mainEncryptDecrpyt(uint32_t activityLevel)
 {
     int choice;
     std::wstring input;
-    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().c_str();;
-    const std::wstring encryptedDataDirPath = std::filesystem::current_path().c_str();
+    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().wstring();
+    const std::wstring encryptedDataDirPath = std::filesystem::current_path().wstring();
     std::wstring encryptedInputFilePath = encryptedDataDirPath + L"\\encrypted";
     std::wstring tagFilePath = encrytedKeyDirPath + L"\\tag";
path: SampleApps/SampleApps/SampleApp1/main.cpp
user: login: Copilot
body: There is a typo in the variable name `encrytedKeyDirPath` (missing 'p'). Consider renaming to `encryptedKeyDirPath` for clarity.
```suggestion
    const std::wstring encryptedKeyDirPath = std::filesystem::current_path().wstring();
    const std::wstring encryptedDataDirPath = std::filesystem::current_path().wstring();
    std::wstring encryptedInputFilePath = encryptedDataDirPath + L"\\encrypted";
    std::wstring tagFilePath = encryptedKeyDirPath + L"\\tag";
``` #Resolved
created_at: 2025-05-21T23:06:42Z
author_association: NONE
diff_hunk: @@ -418,8 +418,8 @@ int mainEncryptDecrpytThreadpool(uint32_t activityLevel)
 
     int choice;
     std::wstring input1, input2;
-    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().c_str();
-    const std::wstring encryptedDataDirPath = std::filesystem::current_path().c_str();
+    const std::wstring encrytedKeyDirPath = std::filesystem::current_path().wstring();
+    const std::wstring encryptedDataDirPath = std::filesystem::current_path().wstring();
     std::wstring encryptedInputFilePath = encryptedDataDirPath + L"\\encrypted";
     std::wstring tagFilePath = encrytedKeyDirPath + L"\\tag";
path: SampleApps/SampleApps/SampleApp1/main.cpp
user: login: Copilot
body: There is a typo in the variable name `encrytedKeyDirPath` (missing 'p'). Consider renaming to `encryptedKeyDirPath` for consistency.
```suggestion
    const std::wstring encryptedKeyDirPath = std::filesystem::current_path().wstring();
    const std::wstring encryptedDataDirPath = std::filesystem::current_path().wstring();
    std::wstring encryptedInputFilePath = encryptedDataDirPath + L"\\encrypted";
    std::wstring tagFilePath = encryptedKeyDirPath + L"\\tag";
``` #Resolved
created_at: 2025-05-21T23:06:42Z
author_association: NONE
diff_hunk: @@ -96,10 +86,19 @@ namespace veil::vtl0
 
             public:
             logger(const std::wstring& providerName,
-                const std::wstring& guidStr,
-                const veil::any::logger::eventLevel level) : provider(providerName), guid(guidStr), logLevel(level)
+               const std::wstring& guidStr,
+               const veil::any::logger::eventLevel level,
+               const std::filesystem::path& logDirectory = std::filesystem::path()) : provider(providerName), guid(guidStr), logLevel(level)
             {
-                SetLogFilePath();
+               if (!logDirectory.empty())
+               {
+                   logFilePath = logDirectory.wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
+               }
+               else
+               {
+                   // Default to the current working directory if no directory is provided
+                   logFilePath = std::filesystem::current_path().wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
path: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
user: login: Copilot
body: Instead of manual string concatenation for file paths, consider using `std::filesystem::path` operations (e.g., `logDirectory / (ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt")`) to improve readability and robustness.
```suggestion
                   logFilePath = (logDirectory / (ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt")).wstring();
               }
               else
               {
                   // Default to the current working directory if no directory is provided
                   logFilePath = (std::filesystem::current_path() / (ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt")).wstring();
``` #Resolved
created_at: 2025-05-21T23:06:42Z
author_association: NONE
diff_hunk: @@ -96,10 +86,19 @@ namespace veil::vtl0
 
             public:
             logger(const std::wstring& providerName,
-                const std::wstring& guidStr,
-                const veil::any::logger::eventLevel level) : provider(providerName), guid(guidStr), logLevel(level)
+               const std::wstring& guidStr,
+               const veil::any::logger::eventLevel level,
+               const std::filesystem::path& logDirectory = std::filesystem::path()) : provider(providerName), guid(guidStr), logLevel(level)
             {
-                SetLogFilePath();
+               if (!logDirectory.empty())
+               {
+                   logFilePath = logDirectory.wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
path: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
user: login: jsidewhite
body: >logFilePath = logDirectory.wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt"; [](http://example.com/codeflow?start=19&length=106)

logFilePath = logDirectory / (ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt");
created_at: 2025-05-23T20:58:08Z
author_association: MEMBER
diff_hunk: @@ -96,10 +86,19 @@ namespace veil::vtl0
 
             public:
             logger(const std::wstring& providerName,
-                const std::wstring& guidStr,
-                const veil::any::logger::eventLevel level) : provider(providerName), guid(guidStr), logLevel(level)
+               const std::wstring& guidStr,
+               const veil::any::logger::eventLevel level,
+               const std::filesystem::path& logDirectory = std::filesystem::path()) : provider(providerName), guid(guidStr), logLevel(level)
             {
-                SetLogFilePath();
+               if (!logDirectory.empty())
+               {
+                   logFilePath = logDirectory.wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
+               }
+               else
+               {
+                   // Default to the current working directory if no directory is provided
+                   logFilePath = std::filesystem::current_path().wstring() + L"\\" + ReplaceForbiddenFilenameChars(CreateTimestamp()) + L".txt";
path: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h
user: login: jsidewhite
body: >.wstring() + [](http://example.com/codeflow?start=64&length=12)

use filesystem
created_at: 2025-05-23T20:58:39Z
author_association: MEMBER

PR comments:
user: login: jsidewhite
created_at: 2025-05-21T22:14:00Z
body: >             std::wstring logFilePath;

in future, consider using std::filesytem::path #Resolved

---
Refers to: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:31 in 5292ef2. [](commit_id = 5292ef2bd3e34251db9372396336d0d96497d268, deletion_comment = False)
author_association: MEMBER
user: login: SohamDas2021
created_at: 2025-05-21T22:16:48Z
body: >             std::wstring logFilePath;

knew this was coming, will fix in future :)

---
In reply to: [2899380200](https://github.com/microsoft/VbsEnclaveTooling/pull/91#issuecomment-2899380200) [](http://example.com/codeflow?ancestors=2899380200)

---
Refers to: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:31 in 5292ef2. [](commit_id = 5292ef2bd3e34251db9372396336d0d96497d268, deletion_comment = False)
author_association: COLLABORATOR
user: login: jsidewhite
created_at: 2025-05-21T22:21:09Z
body: >         class logger

also just noticed that this should be in an "implementation" namespace so users aren't tempted to call it from their VTL0 hostapp code. #Closed

---
Refers to: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:26 in 5292ef2. [](commit_id = 5292ef2bd3e34251db9372396336d0d96497d268, deletion_comment = False)
author_association: MEMBER
user: login: jsidewhite
created_at: 2025-05-21T22:23:30Z
body: >             static void SaveLog(const std::wstring& log, const std::wstring& logPath)

recommend just taking a std::filesytem::path parameter in future #Resolved

---
Refers to: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:78 in 5292ef2. [](commit_id = 5292ef2bd3e34251db9372396336d0d96497d268, deletion_comment = False)
author_association: MEMBER
user: login: jsidewhite
created_at: 2025-05-21T22:28:11Z
body: > }

oh i think we can delete this now - i missed it. #Resolved

---
Refers to: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:18 in 5292ef2. [](commit_id = 5292ef2bd3e34251db9372396336d0d96497d268, deletion_comment = False)
author_association: MEMBER
user: login: SohamDas2021
created_at: 2025-05-21T22:52:10Z
body: >             static void SaveLog(const std::wstring& log, const std::wstring& logPath)

Noted. 

---
In reply to: [2899396121](https://github.com/microsoft/VbsEnclaveTooling/pull/91#issuecomment-2899396121) [](http://example.com/codeflow?ancestors=2899396121)

---
Refers to: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:78 in 5292ef2. [](commit_id = 5292ef2bd3e34251db9372396336d0d96497d268, deletion_comment = False)
author_association: COLLABORATOR
user: login: SohamDas2021
created_at: 2025-05-23T17:52:17Z
body: >         class logger

logger is constructed in the host code.

---
In reply to: [2899392452](https://github.com/microsoft/VbsEnclaveTooling/pull/91#issuecomment-2899392452) [](http://example.com/codeflow?ancestors=2899392452)

---
Refers to: src/VbsEnclaveSDK/src/veil_host_lib/logger.vtl0.h:26 in 5292ef2. [](commit_id = 5292ef2bd3e34251db9372396336d0d96497d268, deletion_comment = False)
author_association: COLLABORATOR