Click here to Skip to main content
15,745,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

Anyone can suggest best practice to log every request/response of Dot net core web API at single place.

For example , Web API is hosted on multiple web server behind load balancer and want to check log in case of incident have to go on multiple web server text log files .

What I have tried:

Currently using Log4Net which is generating text log file on every server
Updated 15-May-23 21:06pm

1 solution

If you're talking an ASP.Net web API server, then read this: Write custom ASP.NET Core middleware | Microsoft Learn[^].
Share this answer
vishal_h 16-May-23 5:14am    
Middleware will write the log but again it will on server where request will received. But I want to check log for particular user then have to check multiple server log files. So Is Microsoft providing any solution for log into centralize server or database any other log provider .
Graeme_Grant 16-May-23 5:41am    
Middleware allows you to capture all inbound and outbound, including the httpcontext and user. ON creation you can inject anything, including loggers.

Once you inject the logger into your custom middleware, the Log4Net loggers that you have configured, will do all the heavy lifting. All that you need to do is log your messages.

Log4Net has many different custom loggers and you can write your own. I have done custom loggers for the top logging framework, including Log4Net: LogViewer Control for WinForms, WPF, and Avalonia in C# & VB[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900