How to integrate elmah logging in a service program

I am new to servicestack and elman registration.

Can any body suggest how we integrate elmah into applications in the application stack.

Thank...

+5
source share
4 answers

If you have an existing logging solution, you can use the ServiceStack.Logging.Elmah project . It is available through NuGet.

Exceptions, errors and fatal calls will be logged at Elmah in addition to the originally scheduled registrar. For all other types of logs, only the source logger is used.

So, if you are already using Log4Net, you can just configure Elmah like this

ElmahLogFactory factory = new ElmahLogFactory(new Log4NetFactory());

, Elmah - ASP.NET. , , ServiceStack.

+4
using ServiceStack.Logging;
using ServiceStack.Logging.Elmah;
using ServiceStack.Logging.NLogger;

public AppHost()
        : base(
            "description", 
            typeof(MyService).Assembly)
    {
        LogManager.LogFactory = new ElmahLogFactory(new NLogFactory());
    }

    public override void Configure(Container container)
    {
        this.ServiceExceptionHandler += (request, exception) =>
            {
                // log your exceptions here
                HttpContext context = HttpContext.Current;
                ErrorLog.GetDefault(context).Log(new Error(exception, context));

                // call default exception handler or prepare your own custom response
                return DtoUtils.HandleException(this, request, exception);
            };

        // rest of your config
    }
}

ServiceStack Elmah ( , web.config ..).

+3

kampsj , Gavin, Gavins elmah, elmah, servicestack ... .

, , , - (, NLog Elmah)

public class YourAppHost : AppHostBase
{
    public YourAppHost() //Tell ServiceStack the name and where to find your web services
        : base("YourAppName", typeof(YourService).Assembly)
    {
        LogManager.LogFactory = new ElmahLogFactory(new NLogFactory());
    }

    //...just normal stuff...
}

:

ElmahLogFactory factory = new ElmahLogFactory();

... , , , Debug and Warn.

+2

Elmah Logging.Elmah UseCase ServiceStack Elmah, .

ElmahLogFactorycan be configured in Global.asaxbefore initializing ServiceStack AppHost, for example:

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        var debugMessagesLog = new ConsoleLogFactory();
        LogManager.LogFactory = new ElmahLogFactory(debugMessagesLog, this);
        new AppHost().Init();
    }
}
0
source

All Articles