Is it possible to set an SMTP header in SMTPAppender? - log4j

I've got an SMTPAppender configured and I'd like to have email messages sent by that appender to have the header Auto-Submitted: auto-generated added to the messages. (This allows auto-responders, for example, to stop sending out-of-office messages to auto-generated error messages).
I don't see anything in the log4j 1.2.x API to handle this kind of thing. Is it possible to do with the existing library? If not, is it possible with a little extra hacking?

It seems as if this capability isn't available with log4j (at least the 1.x line) out of the box.
I've created a class that will do this through configuration. It can be found on GitHub here:
org/apache/log4j/extras/ExtendedSMTPAppender.java

Related

spring integration 4.1.x channel vs message template send operation

In Spring integration app, you can send message to channel in different ways. Two of them are, you can use channel.send(msg) and MessageTemplate.convertAndSend(channel,msg).
Can anyone tell me the difference and which is recommended? What is the drwaback of others?
There is another more high-level way to send message - #MessagingGateway, where your source client is fully free from Messaging API.
On the other hand it is up to use what to use on the matter.
The MessageChannel.send() API is very low and don't provide so much control over the message.
The MessagingTemplate can be configured as a bean with some common options like MessageConverter, which is really used by the aforementioned convertAndSend(). But in the end it is, of course, just MessageChannel.send().
There is no any recommendations, but MessagingTemplate has been introduced for convenience.

How do I reduce the amount of trace logs that Application Insights sends to the server

I'm working with a production system that has a moderate amount of load. The amount of trace events and AI sends up is way too detailed, and makes it difficult to wade through logs later.
Each request to the server has information such as:
Message='Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
and
Message='Action returned 'RZ.API.Support.Controllers.OperationActionResult`1[System.Collections.Generic.List`1[RZ.Entity.System.ClientMessage]]'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync
There are maybe 30 entries for each request!
I just need the request type:
12/16/2015, 9:17:29 AM - REQUEST
GET /api/v1/user/messages
And the result code - as well as any custom stuff I do along the way.
So basically I want to trim most the traces except the request and the result (and any errors etc).
I have my eye on this bad boy in the AI config:
<Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web"/>
... but I cannot for the life of me see any doco on how to ask it to reduce the amount of stuff that is sent!
Any help is much appreciated.
Jordan.
P.S. All the extra logging has put us over the 15m a month plan, we had to upgrade!
RequestTrackingTelemetryModule does not do anything like you described. It adds requests, exceptions and dependencies collection. And in you example you are saying you see verbose WebApi traces being forwarded to ApplicationInsights. I assume you actually use Application Insights logging adapter.
Here you can read how WebApi traces can be forwarded to AI Version 1: http://apmtips.com/blog/2014/11/13/collect-asp-dot-net-mvc-web-api-traces-with-application-insights/
Here you can read how WebApi traces can be forwarded to AI Version 2:
http://apmtips.com/blog/2016/01/05/webapi-tracing-powered-by-ai-in-vs2015-update1/
Source code of logging adapters: https://github.com/Microsoft/ApplicationInsights-dotnet-logging
Documentation: https://azure.microsoft.com/en-us/documentation/articles/app-insights-search-diagnostic-logs/#trace
So you have multiple options:
Do not use logging adapters
Change verbosity of WebApi tracing (read http://www.asp.net/web-api/overview/testing-and-debugging/tracing-in-aspnet-web-api). I would prefer this one since you probably want to collect failures.
Remove WebApi tracing (as you did)
To answer my own question.
In my WebApiConfig file, I had:
config.EnableSystemDiagnosticsTracing();
Removing this line drastically cut down the clutter to what I was trying to achieve.
As of version 2.0 of the Application Insights SDKs, you can also limit the data sent by enabling sampling:
https://azure.microsoft.com/en-us/documentation/articles/app-insights-sampling/
if you add
<MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
to your ApplicationInsights.config, the sdk can limit how much goes out. The article above has a LOT more settings/configuration you can use to get other specific behavior, but the one above is the simplest.
As far as I know there are no configuration options available for the RequestTrackingTelemetryModule. You could just turn it off (by uninstalling the respective NuGet package or commenting the xml) and / or install different / additional telemetry modules.
See app-insights-configuration-with-applicationinsights-config for a list of modules and configuration options.

ActiveMQ send ObjectMessage

I'm using ActiveMQ to implement a messaging system in my current project. I need to send and receive Java objects instead of simple text or binary messages. The Java object (my message object) implements the Serializable interface as required.
Recent versions of ActiveMQ added some security and I need to set a property with the allowed packages as described here, but I haven't managed to make it work. I'm not sure where that property needs to be added.
Error message:
This class is not allowed to be serialized. Add package with 'org.apache.activemq.SERIALIZABLE_PACKAGES' system property
You need to either pass trusted packages in environment variable while running jar or you can do this programmatically by adding following line of code:
System.setProperty("org.apache.activemq.SERIALIZABLE_PACKAGES","*");
I hope this will help
In your ActiveMQ config,add connectionFactory.setTrustedPackages(Arrays.asList("java.lang","your packagename"));

Can CRM 2013 Plugin Trace Information be Obtained Client Side?

In CRM plugins, we use the tracing service to record information:
localContext.Trace("Some useful info");
If I deliberately throw an exception in plugins, I see the trace info in the log file that I can download via the GUI.
If the plugin is being executed by API calls running on a command-line client, (creating/updating the entity that runs the plugin) and an exception is thrown, can I obtain the trace information from the client side?
why do you want to get info from client side into a plugin log? I reckon is possible to obtain those info as part of the submitting process, but you will need additional fields on the entity.
For example you hook the plugin on the update method, you populate a multi-line text field in the entity. That field will be available on the back-end and you will be able to write in the log the content of that multi-line. Even show an Invalid plugin exception containing those information.
Usually for debugging purposes you debug he js via UI while, if you don't have vs on the same machine of crm you use the plugin profiler or the tracing.

How do you add a StackTrace to every log call in log4net?

I'm using Log4Net to log a multilayer-ed Enterprise Application.
I know that when I log an exception with Log4Net, it automatically exposes the exception StackTrace, but I want to log the StackTrace for every log call, even if those are not exception throws.
Why do I need that?...
I want to know the call origin of the log (drilldown the layers...)
Thank all...
Tiago Dias
I came to a solution to my problem.
I've wrap around the log4net in my own methods and i've created LoggingEvent intances. In each instance i've used a property with Environment.StackTrace.
This way i have StackTrace foreach log event in my application, even without exceptions being throwned.
Thank U all..
You can get the caller method name and line number using %location, but not the entire stack trace without extending log4net. Check responses to this question:
Does log4net support including the call stack in a log message
Also check the PatternLayout documentation page on apache.org for other location details you can output:
http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
Not sure if this still applies on modern computers, but the log4net documentation warns that generating caller information is costly.

Resources