NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
862 stars 170 forks source link

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

Closed michaelstum closed 2 years ago

michaelstum commented 3 years ago

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);
    }
}
NickCraver commented 3 years ago

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 :+1: - otherwise will probably poke this weekend.

NickCraver commented 2 years ago

Added in #219!