-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try Catch does not log #51
Comments
Do you mean that you see an error log entry in, say, console but not in the log file? What are your log levels in appsettings.json? |
Yup. For the log level, it is the same as what was documented in the example project you included in this repository. Anyways, here is the appsettings.json: { |
And you have made necessary AddFile calls for all these sections ("FileOne", "FileTwo" etc) and your nuget reference is for the latest version (1.1.6)? Could you confirm that the same happens in https://github.com/nreco/logging/tree/master/examples/TwoLogFilesMvc ? |
Yes I had made the "AddFile" calls, but my package version is 1.0.0 |
You need to reference the last version of NReco.Logging.File which is 1.1.6. I cannot reproduce that in "TwoLogFilesMvc" example. I've added this to LoggingDemoController:
and in the app_debug.log I see
|
Hi, Sorry I made a small mistake. For the version referenced, it is 1.1.6. I had mistaken the version of my project and the added reference. |
If you can to reproduce the issue with an example code please let me know your steps. Most likely something wrong with your app's configuration (I don't have your code and cannot say what is wrong). |
Sure thing, maybe let me try out first, then if the issue still persist, I will send over the example code. |
I think the problem is with your code @ShaunStanley. You catch and handle the exception (no re-throw) and you do not log yourself. So there won't be an UnhandledException and there won't be any log entry. If you handle an exception yourself and you also want it to be logged, you need to log it yourself in the catch handler. |
Hi,
I am new to logging and currently exploring logging frameworks, while testing out this framework, when I have a try catch condition, it seems like the Exception log is not logged. Perhaps anyone could advise regarding this matter?
Here is my test code (using MVC architecture and this section of code is in the controller):
public async Task TestError()
{
int statCode = 0;
string msg = "";
try
{
Guid g = new Guid("ABC"); //Here it will definitely create an error since "ABC" is not a proper Guid format
statCode = 200;
msg = g.ToString();
}
catch (Exception ex)
{
statCode = 500;
msg = ex.ToString();
}
return StatusCode(statCode, msg);
}
Thanks in advance.
The text was updated successfully, but these errors were encountered: