Serilog MinimumLevel.Override - serilog

My question is how granular do I need to be with Serilog MinimumLevel.Override when it comes to the source?
For example I want to have all messages from Microsoft be logged at the Warning Level.
Will the source "Microsoft" be adequate?
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
Or do I need to do something like this:
.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
....

.MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
will cause all events from Microsoft, Microsoft.AspNetCore, Microsoft.AspNetCore.Hosting, etc., to be logged at the Warning level and above. It's not necessary to list every child namespace.

Related

Is there a method in quickfix for returning execution report acknowledgement message?

I have initiator and acceptor applications in Java. I'm using FIX 4.2 protocol.
I'm sending Execution Reports via acceptor and getting them with initiator. There's no problem in here. What I need is, return an execution report acknowledgement message(type: BN) for the acceptor. In FIX 4.2 standarts there are no BN messages. I will probably add those fields to datadictionary myself.
I checked user manual of quickfix. There are some example methods for sending messages.
void sendOrderCancelRequest() throws SessionNotFound
{
quickfix.fix41.OrderCancelRequest message = new quickfix.fix41.OrderCancelRequest(
new OrigClOrdID("123"),
new ClOrdID("321"),
new Symbol("LNUX"),
new Side(Side.BUY));
message.set(new Text("Cancel My Order!"));
Session.sendToTarget(message, "TW", "TARGET");
}
Should i write a method like above and call it inside of onMessage method? How can I response these messages?
QF does not automatically do this for you.
You will need to implement your own logic to create the ack message and send it.
And yes, you are correct that you will need to add BN and its fields to your DataDictionary. I would then recommend that you re-generate the QF/j source and rebuild the library so that you can have proper BN message/field classes. (The QF/j documentation should be able to guide you with this.)

Log4j2 (and SLF4j 2.0.0-alpha1) and JsonTemplateLayout--how to serialize Messages as JSON

I'm exploring Log4j 2.14.0 and SLF4j 2.0 and trying to generate structured messages.
I've got my Appender set up with a slightly modified LogstashJsonEventLayoutV1.json,
<JsonTemplateLayout eventTemplateUri="classpath:LogstashJsonEventLayoutV1-test.json" properties="true" />
where I've removed the timestamp and hostname(I'm doing this as part of a unit test) and modified the config for "message" like so:
"message": {
"$resolver": "message",
"fallbackKey": "formattedMessage"}
When I log something
log4jLogger.atInfo().log(new MapMessage(Map.of("hello", "world")));
It's obviously generating JSONified log messages:
{"#version":1,"message":{"hello":"world"},"thread_name":"Test worker","level":"INFO","logger_name":"java.lang.Integer"}
In production my shop generally uses Log4J via SLF4J. I'd be willing to use the 2.0.0-alpha1 release of SLF4J to achieve this goal. How would I achieve the same thing via SLF4J's fluent API via addKeyValue?
logger.atDebug().addKeyValue("oldT", oldT).addKeyValue("newT", newT).log("Temperature changed.");
At the end of the day I just wrapped log4j--for this use case, there was no manna to be had for wrapping Slf4j when I could just target log4j.

Why MassTransit `ServiceCollectionBusConfigurator` doesn't add `IConsumer` to `DI` by `AddConsumer`?

I am working on Blazor Server .NET 5 project which uses a nice MassTransit 7.0.5-develop2976 framework (thanks Chris by the way!).
I am curious why MassTransit ServiceCollectionBusConfigurator doesn't add consumers to DI when I do .AddConsumer<T>(). As a result, I am getting "Unable to resolve consumer type..." exception like below. See the workaround below.
For instance, similar ServiceCollectionMediatorConfigurator does it when if I add my IConsumer<> type via it.
An example of the exception I am getting when MassTransit tries to resolve my consumer (in my case it happens when a recurring scheduled job is triggered, but it doesn't matter).
MassTransit.ConsumerException: Unable to resolve consumer type 'SomeMyConsumer'.
at MassTransit.ExtensionsDependencyInjectionIntegration.ScopeProviders.DependencyInjectionConsumerScopeProvider.MassTransit.Scoping.IConsumerScopeProvider.GetScope[TConsumer,T](ConsumeContext`1 context)
at MassTransit.Scoping.ScopeConsumerFactory`1.Send[TMessage](ConsumeContext`1 context, IPipe`1 next)
at MassTransit.Pipeline.Filters.ConsumerMessageFilter`2.GreenPipes.IFilter<MassTransit.ConsumeContext<TMessage>>.Send(ConsumeContext`1 context, IPipe`1 next)
The question: what is the reason for such behaviour from an architectural perspective? Am I missing anything?
As a workaround, if you explicitly add your consumer to IServiceCollection like in the example below - the error disappears, of course:
services.AddScoped<SomeMyConsumer>();
... or even just register the same consumer via ServiceCollectionMediatorConfigurator as well:
services.AddMediator(configurator =>
{
configurator.AddConsumer<SomeMyConsumer>();
});
P.S. IMHO, similar abstractions should behave similarly if they use the same method signature, aren't they?

Application insights 2.2.1 in .net core 2.0 - turn off output to debug

This is the same question as this but for the recent version of application insights 2.2.1
Since updating to the 2.2 version the debug output is filled with AI data even if it is disabled the way it used to be done.
Previously AI was enabled in startup and I could do something like this:
services.AddApplicationInsightsTelemetry(options =>
{
options.EnableDebugLogger = false;
options.InstrumentationKey = new ConnectionStringGenerator().GetAITelemetryKey();
});
The new method of adding application insights, per the new VS templates, is to add it in Program.cs like this:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseApplicationInsights(connectionStringGenerator.GetAITelemetryKey())
.UseSerilog()
.Build();
In this case there is no construction that takes any options and if I remove the 'UseApplicationInsights' and revert to the original method it makes no difference. Either way I get the output debug window filled wit AI logs.
In fact, even if there is no method to load AI (i.e. I remove both the 'UseApplicationInsights' and 'AddApplicationInsightsTelemetry' I get the logs.
Thanks for any help.
You can opt out of telemetry (for debug, for example) by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1.
Visual Studio is lighting up Application Insights even if you have no code to enable it. You can create an environment variable, ASPNETCORE_PREVENTHOSTINGSTARTUP = True, to prevent Visual Studio from lighting up Application Insights.
How to do this?
Right click the project in VS, Select Properties.In Debug options add environment variable as shown in below screenshot.

Output Spring-WS Generated WSDL Location

This seems like a simple question to me:
I have a project where I automatically generate a Spring-WS WSDL, something like this:
<sws:dynamic-wsdl id="service"
portTypeName="Service"
locationUri="/Service/"
targetNamespace="http://location.com/Service/schemas/Mos">
<sws:xsd location="classpath:/META-INF/Service.xsd"/>
</sws:dynamic-wsdl>
Is there a way, on application context startup, to output the generated address of the wsdl, including context, location, etc? This would be handy if our integration tests start to fail, we can see if the location of the WSDL has changed.
As far as I know, you can find the WSDL at http://yourHost/yourServletContext/beanId.wsdl. In your case, beanId is 'service'.
Check out 3.7. Publishing the WSDL in the Spring-WS documentation for more information about this subject.
If you plan to expose your XSD's as well, the beanId.xsd (or, in my case the method name in the #Configuration class) format will be used. For instance:
private ClassPathResource exampleXsdResource = new ClassPathResource("example.xsd");
#Bean public SimpleXsdSchema example() {
return new SimpleXsdSchema(exampleXsdResource);
}
This exposes an XSD at http://yourHost/yourServletContext/example.xsd.

Resources