How to track package downloads on Nuget.Server?

We use a private Nuget repository to serve packages on an intranet environment. Can I keep track of which packages are being downloaded to create basic statistics? For example, which packages were downloaded the most, etc.

+4
source share
1 answer

Presumably you have an ASP.NET application that uses the NuGet.Server package.

Then it would be pretty easy to add some entries. You can decorate PackageService:

public class MyPackageService : IPackageService { public MyPackageService(PackageService packageService) { _PackageService = packageService; } private readonly PackageService _PackageService; public void CreatePackage(HttpContextBase context) { _PackageService.CreatePackage(context); } public void DeletePackage(HttpContextBase context) { _PackageService.DeletePackage(context); } public void DownloadPackage(HttpContextBase context) { // LOG HERE Log(context); _PackageService.DownloadPackage(context); } public void PublishPackage(HttpContextBase context) { _PackageService.PublishPackage(context); } } 

and then modify Routes.cs to re-bind to MyPackageService .

 public static class NuGetRoutes { public static void Start() { NinjectBootstrapper.Kernel.Rebind<IPackageService>().To<MyPackageService>(); MapRoutes(RouteTable.Routes); } //... } 
+1
source

Source: https://habr.com/ru/post/1498405/


All Articles