Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elmah error logging, can I just log a message?

Tags:

asp.net

elmah

I just installed Elmah (https://code.google.com/p/elmah/) for my ASP.NET application. Is it possible to log a message without creating an Exception first?

catch(Exception e) {     Exception ex = new Exception("ID = 1", e);     ErrorSignal.FromCurrentContext().Raise(ex); } 

So is it possible to do:

ErrorSignal.FromCurrentContext().log("Hello I am testing Elmah"); 
like image 886
user603007 Avatar asked Aug 08 '13 00:08

user603007


People also ask

How do I view the Elmah error log?

Build the application, run it in the browser, and navigate to http://www.yoursite.com/elmah.axd. You are prompted to log in before you see the content. After a successful authentication, you see a web page to remotely view the entire log of recorded exceptions.

What is Elmah error?

ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.

Does Elmah work with .NET core?

elmah.io for ASP.NET Core supports a range of actions for hooking into the process of logging messages. Hooks are registered as actions when installing the elmah.io middleware: services.


2 Answers

Yes, you can use ErrorSignal without throwing an exception.

ErrorSignal.FromCurrentContext().Raise(new NotSupportedException()); 

For the custom message, you can create a custom exception.

var customEx = new Exception("Hello I am testing Elmah", new NotSupportedException());  ErrorSignal.FromCurrentContext().Raise(customEx); 
like image 125
Chris Schiffhauer Avatar answered Oct 19 '22 03:10

Chris Schiffhauer


Try this

Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception("Your message")); 
like image 20
Yasser Shaikh Avatar answered Oct 19 '22 02:10

Yasser Shaikh