简体   繁体   English

如何在Nuget.Server上跟踪包下载?

[英]How to track packages downloads on Nuget.Server?

We're using private Nuget repository for serving packages in intranet environment. 我们使用私有Nuget存储库来为Intranet环境中的包提供服务。 Is it possible to track what packages are downloaded to create basic statistics? 是否可以跟踪下载哪些包以创建基本统计信息? For example which packages were downloaded the most, etc. 例如,哪些包下载最多,等等。

Presumably you have an ASP.NET application which uses the NuGet.Server package. 大概你有一个使用NuGet.Server包的ASP.NET应用程序。

Then it would be quite easy to add some logging. 然后添加一些日志记录会非常容易。 You can decorate the PackageService: 你可以装饰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 change Routes.cs to rebind to MyPackageService . 然后将Routes.cs更改为重新绑定到MyPackageService

public static class NuGetRoutes {

    public static void Start() {
        NinjectBootstrapper.Kernel.Rebind<IPackageService>().To<MyPackageService>();
        MapRoutes(RouteTable.Routes);
    }

    //...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM