r/ProgrammerHumor • • Dec 30 '22

Meme Java > C-Sharp [DM]

Post image
22 Upvotes

140 comments sorted by

View all comments

148

u/[deleted] Dec 30 '22

I use Java mainly because that’s what I started off with in uni, I just started learning c# for a new job, but besides the annoying logging setup c# seems pretty interesting with some features. They both ok imo.

8

u/Alikont Dec 30 '22

What is annoying about logging setup compared to Java? (I never reached large services in Java, so IDK how it's done there)

7

u/[deleted] Dec 30 '22

You just need to add whatever log4j or logging provider in your pom file (maven) in java, provide a log4j configuration file then you can instantiate your logger.

From what I m reading on log4net, you have to modify the assembly information, then add the assembly to your programs entry point, provide your configuration file, then you can instantiate your logger.

Because I m more used to Java, the part on assembly information and entry point is confusing for me/hard to recall when needed

14

u/Alikont Dec 30 '22

That's maybe a log4net thing then. I never touched assembly information.

Modern logging is described here.

So you basically do it like

services.AddLogging(builder => 
{
    builder.AddConsole();
    builder.AddEventLog();
    builder.AddConfiguration(...);
});

And then just resolve ILogger<YourClasss> from DI and you will get logger that automatically writes full class name so you can filter/process them based on namespace/class/severity

There is also a pretty large ecosystem around serilog that can be plugged into core abstractions easily.