LogReceiverService and Exception/Callsite Info

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

LogReceiverService and Exception/Callsite Info

displaced
LogReceiverService and Exception/Callsite Info

Hi,

I'm attempting to set up a WCF LogReceiverService that can be a log target for all of our projects.  The receiver's own nlog configuration will use a Database target to log all received events to a database.

Although this seems to be running fine, I'm unable to get exception and callsite information sent to the service.  When inspecting the received LogEventInfo object the Exception and HasStackTrace properties are always null/false.  The test client app is certainly using the xxxException(message, exception) methods to send the event.  

Also, there appears to be no way of sending callsite information.

I've temporarily got around this by manually setting parameters in the caller to include this information.  This shows up correctly in the LogEventInfo's properties collection, but this feels like a kludge.

Is there a proper way to achieve this?

Thanks,
Chris
Reply | Threaded
Open this post in threaded view
|

Re: LogReceiverService and Exception/Callsite Info

rschmidt
I am trying to do something similar. Callsite Info seems to be server side. So I am trying to pass my values as parameters. But server side my parameters do not appear in the list of values, they appear in the list of strings. In the list of values there are integer values instead of the text that was passed. The integers seem consistent with the index of the value in the string collection. I am passing the values from the client as follows within the target;

        <parameter name="application" layout="${gdc:item=application}"/>
        <parameter name="customer" layout="${gdc:item=customer}"/>

I am using the processlogmessages method from the sample

        public void ProcessLogMessages(NLog.LogReceiverService.NLogEvents events)
        {
            var baseTimeUtc = new DateTime(events.BaseTimeUtc, DateTimeKind.Utc);            
            var logEvents = new NLog.LogEventInfo[events.Events.Length];              
            // convert transport representation of log events into workable LogEventInfo[]            
            for (int j = 0; j < events.Events.Length; ++j)            
            {                
                var ev = events.Events[j];
                NLog.LogLevel level = NLog.LogLevel.FromOrdinal(ev.LevelOrdinal);                
                string loggerName = events.Strings[ev.LoggerOrdinal];
                var logEventInfo = new NLog.LogEventInfo();                
                logEventInfo.Level = level;                
                logEventInfo.LoggerName = loggerName;                
                logEventInfo.TimeStamp = baseTimeUtc.AddTicks(ev.TimeDelta);                
                logEventInfo.Message = events.Strings[ev.MessageOrdinal];                
                logEventInfo.Properties.Add("ClientName", events.ClientName);                
                for (int i = 0; i < events.LayoutNames.Count; ++i)                
                {                    
                    logEventInfo.Properties.Add(events.LayoutNames[i], ev.Values[i]);                
                }                  
                logEvents[j] = logEventInfo;            
            }              
            this.ProcessLogMessages(logEvents);
        }

These values are logged correctly client side.

Am I passing the values incorrectly or is the sample method incorrect?
Reply | Threaded
Open this post in threaded view
|

Re: LogReceiverService and Exception/Callsite Info

rschmidt
In reply to this post by displaced
@displaced, if you call {callsite} on the server you get the server callsite info. Add the following parm to your client target def;

<parameter name="callsiteInfo" layout="${callsite}" />

then retrieve it on the server with this (this is from a csv target)

<column name="callsiteInfo" layout="${event-context:item=callsiteInfo}" />
Reply | Threaded
Open this post in threaded view
|

Re: LogReceiverService and Exception/Callsite Info

polymute
A slightly more detailed implementation of a LogReceiverService can be found on GitHub - TimberMill.


I logged the exception via a parameter.
eg:

<target xsi:type="LogReceiverService"
            name="TimberMill"
            endpointAddress="http://localhost:6565/Data/LogReceiverService.svc"
            useBinaryEncoding="false"
            clientId="ConsoleAppTester|dev">
            <parameter name="exception" layout="${exception:format=tostring}" />     
        </target>