TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ritu
1.4k
348
43.5k
email notifaication on failure
May 28 2021 9:57 AM
i have working on consuming web api c# console.
i have manage error handling through seprate error handling program using Amazon classes. Now
i want send email when there is any exception and exception is stored in a file.
this is done in Program.cs file in main() method.
ResultToFileModel resultToFile = new ResultToFileModel();
try
{
resultToFile.errors.Add(new ErrorModel
{
CrDatTime = CommonHandler.ConvertDatetime_UTCtoEST(),
LogLevel = LogLevel.Information.ToString(),
MsgDetails = "please check your email",
SourceMethodName = "Service Initiated"
});
}
catch (Exception ex)
{
resultToFile.errors.Add(new ErrorModel
{
CrDatTime = CommonHandler.ConvertDatetime_UTCtoEST(),
LogLevel = LogLevel.Error.ToString(),
MsgDetails = ex.Message,
SourceMethodName = ex.TargetSite.Name
});
string projectLogFolder = Environment.GetEnvironmentVariable("projectLogFolder");
while (ex.InnerException != null)
{
ex = ex.InnerException;
foreach (DictionaryEntry de in ex.Data)
{
resultToFile.errors.Add(new ErrorModel
{
CrDatTime = CommonHandler.ConvertDatetime_UTCtoEST(),
LogLevel = LogLevel.Error.ToString(),
MsgDetails = " Error Description - Key: " + de.Key + " Value: " + de.Value,
SourceMethodName = ex.TargetSite.Name,
JsonErrMessage = ex.Message
});
}
}
string localFileName = string.Empty;
if (resultToFile.errors.Exists(t => t.LogLevel == LogLevel.Error.ToString()))
{
localFileName = resultToFile.fileNameToSave + "_error." + "csv";
}
else
{
localFileName = resultToFile.fileNameToSave + "_success." + "csv";
}
string keyName = projectLogFolder + "/" + localFileName;
SendMail.SendMailMessage(keyName);
}
Reply
Answers (
3
)
How to Validate parameter in asp.net core 3.0 web api's get request?
re-arrange Container.DataItemIndex after merge gridview cell