Added Elmah, Serilog to Server, improved logging
This commit is contained in:
@@ -28,6 +28,7 @@ public class EntityController : ControllerBase
|
||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
||||
} catch (Exception)
|
||||
{
|
||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]); // TODO DRY violation; perhaps move this logging to the SearchdomainManager?
|
||||
return Ok(new EntityQueryResults() {Results = []});
|
||||
}
|
||||
var results = searchdomain_.Search(query);
|
||||
@@ -47,9 +48,9 @@ public class EntityController : ControllerBase
|
||||
{
|
||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception)
|
||||
{
|
||||
_logger.LogError("Unable to retrieve the searchdomain", [ex]);
|
||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
||||
return Ok(new EntityIndexResult() { Success = false });
|
||||
}
|
||||
List<Entity>? entities = searchdomain_.EntitiesFromJSON(JsonSerializer.Serialize(jsonEntity));
|
||||
@@ -73,9 +74,9 @@ public class EntityController : ControllerBase
|
||||
try
|
||||
{
|
||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
||||
} catch (Exception ex)
|
||||
} catch (Exception)
|
||||
{
|
||||
_logger.LogError("Unable to retrieve the searchdomain", [ex]);
|
||||
_logger.LogError("Unable to retrieve the searchdomain {searchdomain} - it likely does not exist yet", [searchdomain]);
|
||||
return Ok(new EntityListResults() { Results = [], Success = false });
|
||||
}
|
||||
EntityListResults entityListResults = new() {Results = [], Success = true};
|
||||
@@ -115,7 +116,7 @@ public class EntityController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet("Delete")]
|
||||
public ActionResult<EntityDeleteResults> Delete(string searchdomain, string entityName) // TODO test this
|
||||
public ActionResult<EntityDeleteResults> Delete(string searchdomain, string entityName)
|
||||
{
|
||||
Searchdomain searchdomain_;
|
||||
try
|
||||
@@ -123,11 +124,13 @@ public class EntityController : ControllerBase
|
||||
searchdomain_ = _domainManager.GetSearchdomain(searchdomain);
|
||||
} catch (Exception)
|
||||
{
|
||||
_logger.LogError("Unable to delete the entity {entityName} in {searchdomain} - the searchdomain likely does not exist", [entityName, searchdomain]);
|
||||
return Ok(new EntityDeleteResults() {Success = false});
|
||||
}
|
||||
Entity? entity_ = searchdomain_.GetEntity(entityName);
|
||||
if (entity_ is null)
|
||||
{
|
||||
_logger.LogError("Unable to delete the entity {entityName} in {searchdomain} - it was not found under the specified name", [entityName, searchdomain]);
|
||||
return Ok(new EntityDeleteResults() {Success = false});
|
||||
}
|
||||
searchdomain_.RemoveEntity(entityName);
|
||||
|
||||
@@ -21,8 +21,16 @@ public class SearchdomainController : ControllerBase
|
||||
[HttpGet("List")]
|
||||
public ActionResult<SearchdomainListResults> List()
|
||||
{
|
||||
var results = _domainManager.ListSearchdomains()
|
||||
?? throw new Exception("Unable to list searchdomains");
|
||||
List<string> results;
|
||||
try
|
||||
{
|
||||
results = _domainManager.ListSearchdomains();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
_logger.LogError("Unable to list searchdomains");
|
||||
throw;
|
||||
}
|
||||
SearchdomainListResults searchdomainListResults = new() {Searchdomains = results};
|
||||
return Ok(searchdomainListResults);
|
||||
}
|
||||
@@ -36,7 +44,8 @@ public class SearchdomainController : ControllerBase
|
||||
return Ok(new SearchdomainCreateResults(){Id = id, Success = true});
|
||||
} catch (Exception)
|
||||
{
|
||||
return Ok(new SearchdomainCreateResults(){Id = null, Success = false});
|
||||
_logger.LogError("Unable to create Searchdomain {searchdomain}", [searchdomain]);
|
||||
return Ok(new SearchdomainCreateResults() { Id = null, Success = false });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,9 +58,9 @@ public class SearchdomainController : ControllerBase
|
||||
{
|
||||
success = true;
|
||||
deletedEntries = _domainManager.DeleteSearchdomain(searchdomain);
|
||||
} catch (Exception ex)
|
||||
} catch (Exception)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
_logger.LogError("Unable to delete searchdomain {searchdomain}", [searchdomain]);
|
||||
success = false;
|
||||
deletedEntries = 0;
|
||||
}
|
||||
@@ -73,7 +82,8 @@ public class SearchdomainController : ControllerBase
|
||||
searchdomain_.helper.ExecuteSQLNonQuery("UPDATE searchdomain set name = @name, settings = @settings WHERE id = @id", parameters);
|
||||
} catch (Exception)
|
||||
{
|
||||
return Ok(new SearchdomainUpdateResults(){Success = false});
|
||||
_logger.LogError("Unable to update searchdomain {searchdomain}", [searchdomain]);
|
||||
return Ok(new SearchdomainUpdateResults() { Success = false });
|
||||
}
|
||||
return Ok(new SearchdomainUpdateResults(){Success = true});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user