TJC.Cyclops.LogLib 2024.9.23.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package TJC.Cyclops.LogLib --version 2024.9.23.3                
NuGet\Install-Package TJC.Cyclops.LogLib -Version 2024.9.23.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TJC.Cyclops.LogLib" Version="2024.9.23.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TJC.Cyclops.LogLib --version 2024.9.23.3                
#r "nuget: TJC.Cyclops.LogLib, 2024.9.23.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TJC.Cyclops.LogLib as a Cake Addin
#addin nuget:?package=TJC.Cyclops.LogLib&version=2024.9.23.3

// Install TJC.Cyclops.LogLib as a Cake Tool
#tool nuget:?package=TJC.Cyclops.LogLib&version=2024.9.23.3                

Cyclops.FrameWork

Cyclops.FrameWork 基于aspnetcore封装的api框架,集成了一线开发的常用设置和基础功能;可以用较少的时间代价,让开发人员将精力更多地集中在业务上。

  • [√] 全局api调用和框架级异常日志,支持Knife4j接口文档的查看、调试和代码生成
  • [√] 接口入参校验,Cyclops.FrameWork中的接口参数校验完全基于System.ComponentModel.DataAnnotations,且在此基础上提供了验证数据是否存在ExistAttribute等扩展功能
  • [√] 统一返回值,无论是使用Cyclops.FrameWork中的Result及其子类,或者CSharp中的裸类型都自动返回全局统一值,从框架上避免对接混乱
  • [√] 标准化快捷文件上传、下载和excel的导入、导出,支持MS Azure和阿里OSS
  • [√] 在安全方面集成jwt认证和SafeComparisonFilter防重放攻击,并且支持多租户权限
  • [√] 标准化配置,支持Nacos

NuGet version (SAEA) License

一、配置示例

{
  "HostingOptions": {
    
    "ServiceName": "Cyclops.WebApplication1",
    "Domain": "https://cyclops.yswenli.com/",
    "EnableHealthCheck": true,
    "AppOptions": {
      "Urls": [ "https://127.0.0.1:7000" ],
      "DisableSwagger": false,
      "HideConsoleLog": false,
      "UseKnife4UI": false,
      //jwt TokenManagement
      "JWTAuthConfig": {
        "Secret": "base64:HU8MlQQDHfGaQ+k+0q3z4HKJvNQUTjK5uRGodDATyKc=",
        "Issuer": "yswenli.cnblogs.com",
        "Audience": "Cyclops.FrameWork",
        "AccessExpiration": 315576000
      },
      "MaxRequestSize": 134217728, //134217728,文件限制128M
      "EnablePartialRequest": false,
      "UserStaticPath": true,
      "StaticPaths": [ "upload" ],
      "DisableSafeComparisonFilter": false,
      "SafeComparisonExpired": 5,
      //全局验证码
      "GloabVerifyCode": "9365",
      //是否启用SignalR
      "EnableSignalR": true,
      //SignalR配置
      "SignalROptions": {
        //SignalR hub url
        "HubUrl": "/hubs/common",
        //握手超时时间
        "HandshakeTimeout": 30,
        //心跳间隔时间
        "KeepAliveInterval": 15,
        //空连接超时时间
        "FreeTimeout": 60,
        //每连接并行处理数量
        "ParallelCount": "1",
        //消息包大小
        "MaximumReceiveMessageSize": 32768
      }
    },
    "NacosConfig": {
      "Listeners": [
        {
          "Optional": false,
          "DataId": "Common",
          "Group": "DEFAULT_GROUP"
        },
        {
          "Optional": false,
          "DataId": "OperationService",
          "Group": "DEFAULT_GROUP"
        }
      ],
      "Namespace": "dev",
      "ServerAddresses": [ "http://127.0.0.1:8848" ],
      "UserName": "",
      "Password": "",
      "ConfigUseRpc": false,
      "NamingUseRpc": false
    }
  }
}


AppConfig节点以下的可以与nacos集成

二、初始化代码示例

public class Program
{
    public static void Main(string args)
    {
        WebApp.OnStarted += WebApp_OnStarted;
        WebApp.OnStopped += WebApp_OnStopped;
        WebApp.RunWebHost<Startup>(args);
    }


    static void WebApp_OnStarted()
    {
        Logger.Info($"{WebApp.ServiceName}应用已启动");
    }


    static void WebApp_OnStopped()
    {
        Logger.Info($"{WebApp.ServiceName}应用已停止");
    }
}
    /// <summary>
    /// Startup
    /// </summary>
    public class Startup : BaseStartup
    {
        /// <summary>
        /// Startup
        /// </summary>
        /// <param name="configuration"></param>
        public Startup(IConfiguration configuration) : base(configuration)
        {

        }
    }

三、控制器示例

继承基类即可

[Route(RouteConst.ROUTE_TEMPLATE_MOBILE)]
public class AuthController : BaseApiController

方法示例

    /// <summary>
    /// Login
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [AllowAnonymous, HttpPost, DisplayName("Login")]
    public async Task<Result> Login([Required(ErrorMessage = "请输入用户名或密码"), FromBody] UserLoginInput input)
    {
        var user = new SysUser();
        return SuccessResult(await CreateToken(user));
    }

    /// <summary>
    /// 获取验证码
    /// </summary>
    /// <returns></returns>
    [AllowAnonymous]
    [SuppressMonitor]
    [DisplayName("获取验证码"), HttpGet]
    public Result GetCaptcha()
    {
        ICaptcha captcha = ServiceProviderUtil.GetRequiredService<ICaptcha>();
        var codeId = YitIdHelper.NextId().ToString();
        var captchas = captcha.Generate(codeId, 180);
        return SuccessResult(new { Id = codeId, Img = captchas.Base64 });
    }

四、集成数据校验

/// <summary>
/// 登录信息
/// </summary>
public class UserLoginInput
{
    /// <summary>
    /// 请输入用户名
    /// </summary>
    [Required(ErrorMessage = "请输入用户名"), Exists("用户名不存在", TableName = "bus_user", ColumnName = "user_name")]
    public string UserName { get; set; }
    /// <summary>
    /// 请输入密码
    /// </summary>
    [Required(ErrorMessage = "请输入密码"), Custom<UserLoginInput>("密码不正确", "Valide")]
    public string Password { get; set; }

    /// <summary>
    /// 验证密码
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public bool Valide(object? input)
    {
        if (input == null) return false;
        if (input is string password && password == "123456")
        {
            return true;
        }
        return false;

    }
}

五、防重放攻击示例

    /// <summary>
    /// 接口安全参数校验测试
    /// </summary>
    [SafeComparisonFilter]
    public class SafeController : BaseApiController
    {
        /// <summary>
        /// Test
        /// </summary>
        /// <param name="testInfo"></param>
        /// <returns></returns>
        [HttpPost]
        public Result Test([FromBody] TestInfo testInfo)
        {
            return SuccessResult(testInfo);
        }

        /// <summary>
        /// test2
        /// </summary>
        /// <returns></returns>
        [HttpGet, AllowAnonymous, NoSafeComparisonFilter]
        public Result Test2()
        {
            return SuccessResult();
        }
    }

六、文件上传下载Excel导入导出示例

   public class FileAdminController : BaseApiController
   {
       /// <summary>
       /// 导入
       /// </summary>
       /// <returns></returns>
       [HttpPost]
       [NoLoginAuth, AllowAnonymous]
       public Result Import(IFormCollection collection)
       {
           var data = collection.SaveAsDataTable();
           return SuccessResult(data);
       }


       /// <summary>
       /// 导出
       /// </summary>
       /// <returns></returns>
       [HttpPost]
       [NoLoginAuth, AllowAnonymous]
       public IActionResult Export()
       {
           return _env.Download("export.png");
       }

       /// <summary>
       /// 导出数据文件
       /// </summary>
       /// <returns></returns>
       [HttpGet]
       [NoLoginAuth, AllowAnonymous]
       public IActionResult ExportFile([FromQuery] bool isExcel = false)
       {
           var fileName = "export.xlsx";
           if (!isExcel)
           {
               fileName = "export.csv";
           }
           var dt = new DataTable();
           //return _env.ExportFile(dt, fileName);
           return Export(dt, fileName);
       }


       /// <summary>
       /// 导出数据文件
       /// </summary>
       /// <returns></returns>
       [HttpGet]
       [NoLoginAuth, AllowAnonymous]
       public IActionResult ExportDataFile([FromQuery] bool isExcel = false)
       {
           var fileName = "export.xlsx";
           if (!isExcel)
           {
               fileName = "export.csv";
           }
           var list = new List<BusUser>
           {
               new BusUser()
               {
                   Id = 1,
                   UserName = "张三"
               }
           };
           //return _env.ExportFile(list, fileName);
           return Export(list, fileName);
       }



       /// <summary>
       /// 测试上传文件大小
       /// </summary>
       /// <returns></returns>
       [HttpPost]
       public async Task<IActionResult> UploadFile(IFormCollection form)
       {
           var fileStream = await form.SaveAsStreamsAsync();

           return fileStream.First().Value.Download("test.jpg");
       }

       /// <summary>
       /// 测试限制上传文件大小
       /// </summary>
       /// <param name="form"></param>
       /// <returns></returns>

       [HttpPost, RequestSizeLimit(2 * 1024 * 1024)]
       public async Task<IActionResult> UploadFileByLimit(IFormCollection form)
       {
           var fileStream = await form.SaveAsStreamsAsync();

           return fileStream.First().Value.Download("test.jpg");
       }

       /// <summary>
       /// 测试不限制上传文件大小
       /// </summary>
       /// <param name="form"></param>
       /// <returns></returns>

       [HttpPost, DisableRequestSizeLimit]
       public async Task<IActionResult> UploadFileByNonLimit(IFormCollection form)
       {
           var fileStream = await form.SaveAsStreamsAsync();

           return fileStream.First().Value.Download("test.jpg");
       }       

      /// <summary>
      /// 示例获取流
      /// </summary>
      /// <returns></returns>
      [HttpGet]
      public async Task<Stream> GetStream()
      {
          var ms = new MemoryStream(RandomUtil.GetBytes(1024));
          return await Task.FromResult(ms);
      }

      /// <summary>
      /// 示例获取字节数组
      /// </summary>
      /// <returns></returns>
      [HttpGet]
      public async Task<byte> GetBytes()
      {
          return await Task.FromResult(RandomUtil.GetBytes(1024));
      }
   }

七、支持非api接口内容

        /// <summary>
        /// 返回指定内容结果
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="text"></param>
        /// <param name="contentType"></param>
        /// <param name="statusCode"></param>
        /// <returns></returns>
        public async Task<IActionResult> ContentAsync(string text, string contentType = "text/plain", int statusCode = 200)
        {
            var contentResult = new ContentResult()
            {
                Content = text,
                ContentType = contentType,
                StatusCode = statusCode
            };
            return await Task.FromResult(contentResult);
        }

        /// <summary>
        /// 返回空结果
        /// </summary>
        /// <param name="controller"></param>
        /// <returns></returns>
        public async Task<IActionResult> EmptyAsync()
        {
            return await Task.FromResult(new EmptyResult());
        }

        /// <summary>
        /// 返回下载结果
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="fileContent">下载时的文件名称</param>
        /// <param name="fileContent">内容字节数组</param>
        /// <param name="contentType">内容mime类型</param>
        /// <returns></returns>
        public async Task<IActionResult> DownloadAsync(string fileDownloadName,
            byte fileContent,
            string contentType)
        {
            return await Task.FromResult(new FileContentResult(fileContent, contentType) { FileDownloadName = fileDownloadName });
        }

        /// <summary>
        /// 返回下载结果
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="fileName">内容文件地址</param>
        /// <param name="contentType">内容mime类型</param>
        /// <returns></returns>
        public async Task<IActionResult> DownloadAsync(string fileName,
            string contentType)
        {
            return await Task.FromResult(new VirtualFileResult(fileName, contentType)
            {
                EnableRangeProcessing = true,
                FileDownloadName = PathUtil.GetFileName(fileName)
            });
        }
        /// <summary>
        /// 返回流结果
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="fileDownloadName"></param>
        /// <param name="fileStream"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        public async Task<IActionResult> DownloadAsync(string fileDownloadName,
            Stream fileStream,
            string contentType
            )
        {
            return await Task.FromResult(new FileStreamResult(fileStream, contentType)
            {
                EnableRangeProcessing = true,
                FileDownloadName = fileDownloadName
            });
        }
        /// <summary>
        /// 返回跳转结果
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task<IActionResult> RedirectAsync(string url)
        {
            return await Task.FromResult(new RedirectResult(url));
        }
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TJC.Cyclops.LogLib:

Package Downloads
TJC.Cyclops.Web.Core

企服版框架中api核心功能项目

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2025.3.26.2 45 3/26/2025
2025.3.26.1 51 3/26/2025
2025.3.25.1 60 3/25/2025
2025.3.24.1 54 3/24/2025
2025.3.18.2 147 3/18/2025
2025.3.18.1 146 3/18/2025
2025.3.13.1 155 3/13/2025
2025.3.12.1 174 3/12/2025
2025.3.11.1 180 3/11/2025
2025.3.10.1 178 3/10/2025
2025.3.6.2 225 3/6/2025
2025.3.5.1 220 3/5/2025
2025.3.3.1 175 3/3/2025
2025.2.28.1 117 2/28/2025
2025.2.25.1 110 2/25/2025
2025.2.23.1 96 2/24/2025
2025.2.14.1 118 2/14/2025
2025.2.7.2 110 2/7/2025
2025.2.7.1 102 2/7/2025
2025.2.6.1 112 2/6/2025
2025.1.22.1 113 1/22/2025
2025.1.21.1 106 1/21/2025
2025.1.20.1 128 1/20/2025
2025.1.16.1 118 1/16/2025
2025.1.9.1 141 1/9/2025
2025.1.8.3 102 1/8/2025
2025.1.8.2 87 1/8/2025
2025.1.8.1 92 1/8/2025
2025.1.7.1 101 1/7/2025
2025.1.3.1 140 1/3/2025
2025.1.2.1 118 1/2/2025
2024.12.31.2 110 12/31/2024
2024.12.31.1 109 12/31/2024
2024.12.30.3 115 12/30/2024
2024.12.30.2 111 12/30/2024
2024.12.30.1 105 12/30/2024
2024.12.27.1 117 12/27/2024
2024.12.26.1 106 12/26/2024
2024.12.25.2 120 12/25/2024
2024.12.25.1 125 12/25/2024
2024.12.24.1 108 12/24/2024
2024.12.19.2 187 12/19/2024
2024.12.19.1 121 12/19/2024
2024.12.18.1 134 12/18/2024
2024.12.17.2 141 12/17/2024
2024.12.17.1 124 12/17/2024
2024.12.16.1 144 12/16/2024
2024.12.12.1 132 12/13/2024
2024.12.11.2 119 12/11/2024
2024.12.10.3 141 12/10/2024
2024.12.10.2 111 12/10/2024
2024.12.10.1 115 12/10/2024
2024.12.9.1 111 12/9/2024
2024.12.6.1 131 12/6/2024
2024.12.5.1 139 12/5/2024
2024.12.4.1 130 12/4/2024
2024.12.3.2 149 12/3/2024
2024.12.3.1 119 12/3/2024
2024.12.2.2 115 12/2/2024
2024.12.2.1 115 12/2/2024
2024.11.29.2 135 11/29/2024
2024.11.29.1 118 11/29/2024
2024.11.28.1 135 11/28/2024
2024.11.27.4 128 11/27/2024
2024.11.27.3 116 11/27/2024
2024.11.27.2 113 11/27/2024
2024.11.27.1 125 11/27/2024
2024.11.26.3 124 11/26/2024
2024.11.26.2 117 11/26/2024
2024.11.26.1 116 11/26/2024
2024.11.25.5 112 11/25/2024
2024.11.25.4 100 11/25/2024
2024.11.25.3 108 11/25/2024
2024.11.25.2 117 11/25/2024
2024.11.25.1 119 11/25/2024
2024.11.23.2 137 11/23/2024
2024.11.23.1 153 11/23/2024
2024.11.22.1 142 11/22/2024
2024.11.21.1 152 11/21/2024
2024.11.20.3 132 11/20/2024
2024.11.20.2 120 11/20/2024
2024.11.20.1 126 11/20/2024
2024.11.19.1 125 11/19/2024
2024.11.18.4 124 11/18/2024
2024.11.18.3 113 11/18/2024
2024.11.18.2 115 11/18/2024
2024.11.18.1 116 11/18/2024
2024.11.14.2 126 11/14/2024
2024.11.14.1 139 11/14/2024
2024.11.13.2 132 11/13/2024
2024.11.13.1 125 11/13/2024
2024.11.12.2 141 11/12/2024
2024.11.12.1 124 11/12/2024
2024.11.11.1 139 11/11/2024
2024.11.8.1 127 11/8/2024
2024.11.6.1 123 11/6/2024
2024.11.5.1 117 11/5/2024
2024.10.29.2 127 10/29/2024
2024.10.29.1 122 10/29/2024
2024.10.28.1 127 10/28/2024
2024.10.25.1 118 10/25/2024
2024.10.24.1 111 10/24/2024
2024.10.21.1 128 10/21/2024
2024.10.18.2 147 10/18/2024
2024.10.18.1 152 10/18/2024
2024.10.16.1 122 10/16/2024
2024.10.12.1 125 10/12/2024
2024.10.11.1 128 10/11/2024
2024.10.10.1 125 10/10/2024
2024.10.9.1 133 10/9/2024
2024.10.8.1 123 10/8/2024
2024.9.26.1 372 9/26/2024
2024.9.25.1 134 9/25/2024
2024.9.23.4 131 9/23/2024
2024.9.23.3 122 9/23/2024
2024.9.23.2 122 9/23/2024
2024.9.23.1 115 9/23/2024
2024.9.19.1 129 9/19/2024
2024.9.14.1 144 9/14/2024
2024.9.10.3 158 9/10/2024
2024.9.10.2 192 9/10/2024
2024.9.10.1 150 9/10/2024
2024.9.5.1 159 9/5/2024
2024.8.22.1 189 8/22/2024
2024.8.21.1 162 8/21/2024
2024.8.19.1 188 8/19/2024
2024.8.15.1 162 8/15/2024
2024.8.14.1 166 8/14/2024
2024.8.13.2 172 8/13/2024
2024.8.13.1 158 8/13/2024
2024.8.12.2 154 8/12/2024
2024.8.12.1 158 8/12/2024
2024.8.9.2 152 8/9/2024
2024.8.9.1 149 8/9/2024
2024.8.7.1 145 8/7/2024
2024.8.6.2 133 8/6/2024
2024.8.6.1 138 8/6/2024
2024.8.5.5 118 8/5/2024
2024.8.5.4 119 8/5/2024
2024.8.5.3 129 8/5/2024
2024.8.5.2 119 8/5/2024
2024.8.5.1 122 8/5/2024
2024.8.2.4 128 8/2/2024
2024.8.2.3 128 8/2/2024
2024.8.2.2 120 8/2/2024
2024.8.2.1 113 8/2/2024
2024.8.1.1 142 8/1/2024
2024.7.31.2 106 7/31/2024
2024.7.31.1 97 7/31/2024
2024.7.25.1 101 7/25/2024
2024.7.17.1 160 7/17/2024
2024.7.12.2 140 7/12/2024
2024.7.12.1 151 7/12/2024
2024.7.11.2 134 7/11/2024
2024.7.11.1 120 7/11/2024
2024.7.10.4 144 7/10/2024
2024.7.10.3 183 7/10/2024
2024.7.10.2 135 7/10/2024
2024.7.10.1 129 7/10/2024
2024.5.29.1 203 5/29/2024
2024.5.28.1 196 5/28/2024
2024.5.15.1 198 5/15/2024
2024.5.13.1 159 5/13/2024
2024.5.11.1 148 5/11/2024
2024.3.15.1 176 3/15/2024
2024.1.9.1 184 1/9/2024
2024.1.4.1 166 1/4/2024
2024.1.2.3 265 1/2/2024
2024.1.2.2 176 1/2/2024
2024.1.2.1 180 1/2/2024
2023.12.29.3 168 12/29/2023
2023.12.29.2 152 12/29/2023
2023.12.29.1 188 12/29/2023
2023.12.28.4 181 12/28/2023
2023.12.28.3 186 12/28/2023
2023.12.28.2 172 12/28/2023
2023.12.28.1 169 12/28/2023
2023.12.27.2 156 12/27/2023
2023.12.27.1 159 12/27/2023
2023.12.26.1 161 12/26/2023
2023.12.25.1 153 12/25/2023
2023.12.22.4 174 12/22/2023
2023.12.22.3 153 12/22/2023
2023.12.22.2 149 12/22/2023
2023.12.22.1 152 12/22/2023
2023.12.21.2 174 12/21/2023
2023.12.21.1 157 12/21/2023
2023.12.20.2 163 12/20/2023
2023.12.20.1 166 12/20/2023
2023.12.14.4 192 12/14/2023
2023.12.14.3 134 12/14/2023
2023.12.14.2 143 12/14/2023
2023.12.14.1 175 12/14/2023
2023.12.13.9 166 12/14/2023
2023.12.13.8 143 12/14/2023
2023.12.13.7 165 12/13/2023
2023.12.13.6 154 12/13/2023

企服版框架集成日志核心