Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering ASP.NET Web API

You're reading from  Mastering ASP.NET Web API

Product type Book
Published in Aug 2017
Publisher Packt
ISBN-13 9781786463951
Pages 330 pages
Edition 1st Edition
Languages
Author (1):
Mithun Pattankar Mithun Pattankar
Profile icon Mithun Pattankar
Toc

Table of Contents (14) Chapters close

Preface 1. Introduction to Microservices and Service-Oriented Architecture 2. Understanding HTTP and REST 3. Anatomy of ASP.NET Core Web API 4. Controllers, Actions, and Models 5. Implementing Routing 6. Middleware and Filters 7. Perform Unit and Integration Testing 8. Web API Security 9. Integration with Database 10. Error Handling, Tracing, and Logging 11. Optimization and Performance 12. Hosting and Deployment 13. Modern Web Frontends

Logging errors to a database using Serilog

Serilog is a third-party logging package for .NET applications. It focuses on fully structured events. It's known for simple APIs, easy setup, and lots of packages to log to various sources, such as files, databases, ElasticSearch, Raygun, and so on.

We will write log information to a database (an MS SQL Server database, that is) using Serilog.Sinks.MSSqlServer. We will add the following packages using the NuGet package manager:

Serilog: 2.5.1-dev-00873
Serilog.Sinks.MSSqlServerCore: 1.1.0 

For database logging, we need a database server location, name, and table. Open appsettings.json to add these configuration settings:

    "Serilog": { 
      "ConnectionString":"Server=.\\sqlexpress;
Database=MyWalletLogDB;trusted_connection=true",
"TableName": "Logs" }

Run the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}