Domanda

Ho un assembly di libreria che emette le informazioni di analisi, e un'applicazione client WinForms che aggiunge un listener di analisi tramite app.config. Se dovessi usare la libreria in ASP.NET, non configurato per System.Diagnostics tracing, come potrei 'catturare' l'output di analisi?

Domanda bonus: Posso fare qualcosa con Elmah per catturare e registrare queste informazioni? La nostra applicazione ASP.NET utilizza attualmente Elmah per la registrazione degli errori, ma questo è tutto quello che so su quel lato delle cose.

È stato utile?

Soluzione

scrivere il codice per il collegamento di un file di traccia ascoltatore a livello di codice e attivare l'analisi nel web.config - si sarà fatto dopo che

Altri suggerimenti

Credo che, fino a quando le uscite della biblioteca rintracciare informazioni, queste informazioni potrebbero essere catturate con qualsiasi attrezzo specializzato (come DebugView ) o anche un utensile casa cresciuto, indipendentemente dalla configurazione ASP.NET.

I vedere questo è vecchio e ha risposto, ma .. Ho appena avuto lo stesso problema e sono arrivato fino a

classe Exception per TraceListener

namespace TrueNorth.Elmah.TraceListener
{
    internal class TraceInformation : Exception
    {
        internal TraceInformation(string message) : base(message){}
    }

    internal class TraceError: Exception
    {
        internal TraceError(string message) : base(message) { }
    }

    internal class TraceWarning : Exception
    {
        internal TraceWarning(string message) : base(message) { }
    }

    internal class TraceWrite : Exception
    {
        internal TraceWrite(string message) : base(message) { }
    }
}

L'ascoltatore

namespace TrueNorth.Elmah.TraceListener
{
    internal class ElmahListener : System.Diagnostics.TraceListener
    {
        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format, params object[] args)
        {
            TraceEvent(eventCache, source, eventType, id, string.Format(format, args));
        }
        public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) //
        {
            Exception exception;
            switch (eventType)
            {
                case TraceEventType.Information:
                    exception = new TraceInformation(message);
                    break;
                case TraceEventType.Error:
                    exception = new TraceError(message);
                    break;
                case TraceEventType.Warning:
                    exception = new TraceWarning(message);
                    break;
                default:
                    exception = new TraceWrite(message);
                    break;
            }
            if (HttpContext.Current.Session == null)
            {
                ErrorLog.GetDefault(null).Log(new Error(exception));
            }
            else
            {
                ErrorSignal.FromCurrentContext().Raise(exception );
            }
        }
        public override void TraceTransfer(TraceEventCache eventCache, string source, int id, string message, Guid relatedActivityId)
        {
            base.TraceTransfer(eventCache, source, id, message, relatedActivityId);
        }
        public override void Write(string message)
        {
        }
        public override void WriteLine(string message)
        {
        }
    }
}

E, il codice GO (è possibile utilizzare il web.config)

Tracer.Register();

http : //truenorthit.co.uk/2015/04/17/trace-listener-for-elmah-asp-mvc-exception-logger/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top