Changed to log error details in addition to file name

This commit is contained in:
Rob King
2015-06-04 21:01:35 +01:00
parent 67de77fe08
commit 8421b2f7e8
2 changed files with 10 additions and 22 deletions

View File

@@ -36,18 +36,15 @@ namespace Orchard.Recipes.Services {
var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes");
var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true);
recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r =>
{
var recipe = _recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r));
recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r => {
if (recipe == null)
{
Logger.Error(new Exception(string.Format("Invalid recipe file: {0}", r)), "Invalid recipe file: {0}", r);
try {
recipes.Add(_recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r)));
}
else
{
recipes.Add(recipe);
catch (Exception ex) {
Logger.Error(new Exception(string.Format("Invalid recipe file: {0}\nError: {1}", r, ex.Message)), "Invalid recipe file: {0}\nError: {1}", r, ex.Message);
}
});
}
else {

View File

@@ -20,21 +20,12 @@ namespace Orchard.Recipes.Services {
var recipe = new Recipe();
try {
if (string.IsNullOrEmpty(recipeText))
{
return null;
if (string.IsNullOrEmpty(recipeText)) {
throw new Exception("Recipe is empty");
}
XElement recipeTree;
try
{
recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
}
catch
{
return null;
}
XElement recipeTree = XElement.Parse(recipeText, LoadOptions.PreserveWhitespace);
var recipeSteps = new List<RecipeStep>();