In my test application I'd like to output a .txt file or .etl log in the user of the app's directory.
For example, one thing I'd like to test is a camera's exposure. And I want the result to be returned in either a .txt file or log .etl file.
var exposureControl = _mediaCapture.VideoDeviceController.ExposureControl;
var outOfRangeValue = 0; // milliseconds
if (exposureControl.Min.Millieseconds > outOfRangeValue) {
textFile.add("Passed: Minimum Exposure" + exposureControl.Min.Millieseconds.ToString() + " is greater than " + outOfRangeValue.ToString()");
} else {
textFile.add("Failed: Minimum Exposure " + exposureControl.Min.Millieseconds.ToString() + " should not be less than " + outOfRangeValue.ToString() + " bc app will crash");
}
Then on the device using this Windows 10 UWP app, the text file or .etl log created should include one of the below strings:
Passed: Minimum Exposure 0.06 is greater than 0
or
Failed: Minimum Exposure 0.06 should not be less than 0
Thus I essentially need something that acts as my fake textFile.add("")
cmd.
What would be the best method to do this?
I've looked into loggers such as MetroLog and Serilog. And Microsoft's Logging Sample:https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Logging. And another Microsoft example: https://code.msdn.microsoft.com/windowsapps/Logging-Sample-for-Windows-0b9dffd7#content. And this blogger's example as well: http://cryclops.com/2014/01/not-so-stupid-simple-logging-for-windows-store-apps-in-cvb/
I've tried to implement MetroLog and the both Microsoft examples referenced above and I cannot confrim where files are being created. Regardless, I'm not even sure if these are the best methods for my desired results.
If you want to do this without a Logger, you can do something like the following:
private async Task AddTextToFile(String textToSave)
{
var appFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
var file = await appFolder.CreateFileAsync("exposure.txt",
Windows.Storage.CreationCollisionOption.OpenIfExists);
await Windows.Storage.FileIO.AppendTextAsync(file, textToSave + Environment.NewLine);
// Look in Output Window of Visual Studio for path to file
System.Diagnostics.Debug.WriteLine(String.Format("File is located at {0}", file.Path.ToString()));
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
await AddTextToFile(String.Format("MinimumExposure {0}", DateTime.Now.Millisecond.ToString()));
}
As kennyzx says, this file is in a hidden directory, so I've added a Debug.WriteLine() command so that you can see the location of the file in Visual Studio's Output Window when running the app in Debug mode. If you use this code, you will likely want to remove that line.