简体   繁体   中英

Change MetroLog folder and file name in Windows 10 UWP app

Wondering if anybody has experience using MetroLog on a Windows 10 UWP app. I am not too familiar with it and just started using it. For the purpose of not duplicating code and creating a long post, I followed this walk through step by step.

The question I have is a simple one though. With this guide and the default implementation of MetroLog, the log files are stored in a folder named "MetroLog" within my app local folder. Furthermore, the file name is just named "log - 20170206.log"

I want to customize the path and the filename. First, I want the path to just be my application root local folder path and not in another subfolder named MetroLog. I also want the log file to be the name of my application instead of just "log".

For example, I want my folder and file name to be like the following:

private const string logFileName = @"MyAppName.log";
var filePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, logFileName);

I know the logger uses a StreamingFileTarget but I did not see that I could specify the path and file name.

Thoughts?

First, I want the path to just be my application root local folder path and not in another subfolder named MetroLog.

If you've checked the source code of MetroLog on github, you'll find that creating "MetroLog" subfolder is in "MetroLog.Shared.WinRT" project. Line 34 This subfolder path is fixed in its source code.

I also want the log file to be the name of my application instead of just "log".

The same thing, you'll see the naming method of creating log file is in the "MetroLog.Shared" project. Line 33

So, if you want to get your target, you'll need to change the two places in that source code. And rebuild a custom version. After that, you could add reference to your custom version "MetroLog" library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM