NickCraver/StackExchange.Exceptional

Could JSONErrorStore create the Path if it doesn't exist yet?

Closed this issue · 2 comments

If I use the JSONErrorStore with a Path that doesn't exist yet, Exceptional blows up with an IOException, Could not find a part of the path.

Wondering if the path could be automatically created for me (similar to e.g., most loggers that will create whatever directories they need) instead. Not sure if that should be an option or just implicitly done.

Currently using this in my Startup code as a workaround:

var exceptionalPath = Configuration.GetSection("Exceptional")?.GetSection("Store")?.GetSection("Path").Value;
if (!string.IsNullOrEmpty(exceptionalPath))
{
    exceptionalPath = StackExchange.Exceptional.Internal.InternalExtensions.ResolvePath(exceptionalPath);
    if (!System.IO.Directory.Exists(exceptionalPath))
    {
        System.IO.Directory.CreateDirectory(exceptionalPath);
    }
}

I don't think it should happen by default (because the folder ACL would belong to the app, potentially hosing external aggregators, etc.), but as an option: yeah sure, absolutely. If you want to fire up a PR to add it to that provider 👍 - otherwise will probably poke this weekend.

Added in #219!