点击或拖拽改变大小

LogStatistics 类

一个统计次数的辅助类,可用于实现分析一些次数统计信息,比如统计某个API最近每天的访问次数, 统计日志组件最近每天访问的次数,调用者只需要关心统计方式和数据个数,详细参照API文档。
An auxiliary class for counting the number of times, which can be used to realize the analysis of some number of times statistical information, such as counting the number of daily visits of an API, and counting the number of daily visits of the log component. The caller only needs to care about the statistical method and the number of data. Refer to details API documentation.
继承层次
SystemObject
  HslCommunication.LogNetLogStatisticsBaseInt64
    HslCommunication.LogNetLogStatistics

命名空间:  HslCommunication.LogNet
程序集:  HslCommunication (在 HslCommunication.dll 中) 版本:11.8.2.0 (11.8.2.0)
语法
public class LogStatistics : LogStatisticsBase<long>

LogStatistics 类型公开以下成员。

构造函数
  名称说明
公共方法LogStatistics
实例化一个新的数据统计内容,需要指定当前的时间统计方式,按小时,按天,按月等等,还需要指定统计的数据数量,比如按天统计30天。
To instantiate a new data statistics content, you need to specify the current time statistics method, by hour, by day, by month, etc., and also need to specify the number of statistics, such as 30 days by day.
Top
属性
  名称说明
公共属性ArrayLength
获取当前的统计类信息的数据总量
Get the total amount of current statistical information
(继承自 LogStatisticsBaseT。)
公共属性GenerateMode
获取当前的统计类信息时间统计规则
Get the current statistical information time statistics rule
(继承自 LogStatisticsBaseT。)
公共属性TotalSum
获取当前的所有的值的总和
Get the sum of all current values
Top
方法
  名称说明
公共方法Equals (继承自 Object。)
受保护的方法Finalize (继承自 Object。)
公共方法GetDataMarkFromDateTime
根据指定的时间,获取到该时间指定的数据标记信息
According to the specified time, get the data mark information specified at that time
(继承自 LogStatisticsBaseT。)
公共方法GetDataMarkFromTimeNow
根据当前数据统计的时间模式,获取最新的数据标记信息
Obtain the latest data mark information according to the time mode of current data statistics
(继承自 LogStatisticsBaseT。)
公共方法GetHashCode (继承自 Object。)
公共方法GetStatisticsSnapAndDataMark
获取当前的统计信息的数据快照,这是数据的副本,修改了里面的值不影响
Get a data snapshot of the current statistics. This is a copy of the data. Modifying the value inside does not affect
(继承自 LogStatisticsBaseT。)
公共方法GetStatisticsSnapshot
获取当前的统计信息的数据快照,这是数据的副本,修改了里面的值不影响
Get a data snapshot of the current statistics. This is a copy of the data. Modifying the value inside does not affect
(继承自 LogStatisticsBaseT。)
公共方法GetStatisticsSnapshotByTime
根据指定的时间范围来获取统计的数据信息快照,包含起始时间,包含结束时间,这是数据的副本,修改了里面的值不影响
Get a snapshot of statistical data information according to the specified time range, including the start time, also the end time. This is a copy of the data. Modifying the value inside does not affect
(继承自 LogStatisticsBaseT。)
公共方法GetType (继承自 Object。)
公共方法LoadFromBinary
从二进制的数据内容加载,会对数据的合法性进行检查,如果数据不匹配,会报异常
Loading from the binary data content will check the validity of the data. If the data does not match, an exception will be reported
公共方法LoadFromFile
从指定的文件加载对应的统计信息,通常是调用SaveToFile(String)方法存储的文件,如果文件不存在,将会跳过加载
Load the corresponding statistical information from the specified file, usually the file stored by calling the SaveToFile(String) method. If the file does not exist, the loading will be skipped
受保护的方法MemberwiseClone (继承自 Object。)
公共方法Reset
重置当前的统计信息,需要指定统计的数据内容,最后一个数据的标记信息,本方法主要用于还原统计信息
To reset the current statistical information, you need to specify the content of the statistical data, and the tag information of the last data. This method is mainly used to restore statistical information
(继承自 LogStatisticsBaseT。)
公共方法SaveToBinary
将当前所有的数据都写入到二进制的内存里去,可以用来写入文件或是网络发送。
Write all current data into binary memory, which can be used to write files or send over the network.
公共方法SaveToFile
将当前的统计信息及数据内容写入到指定的文件里面,需要指定文件的路径名称
Write the current statistical information and data content to the specified file, you need to specify the path name of the file
公共方法StatisticsAdd
新增一个统计信息,将会根据当前的时间来决定插入数据位置,如果数据位置发生了变化,则数据向左发送移动。如果没有移动或是移动完成后,最后一个数进行新增数据 frequency 次
Adding a new statistical information will determine the position to insert the data according to the current time. If the data position changes, the data will be sent to the left. If there is no movement or after the movement is completed, add data to the last number frequency times
公共方法StatisticsAddByTime
新增一个统计信息,将会根据指定的时间来决定插入数据位置,如果数据位置发生了变化,则数据向左发送移动。如果没有移动或是移动完成后,最后一个数进行新增数据 frequency 次
Adding a new statistical information will determine the position to insert the data according to the specified time. If the data position changes, the data will be sent to the left. If there is no movement or after the movement is completed, add data to the last number frequency times
受保护的方法StatisticsCustomAction(FuncT, T)
新增一个统计信息,将会根据当前的时间来决定插入数据位置,如果数据位置发生了变化,则数据向左发送移动。如果没有移动或是移动完成后,最后一个数进行自定义的数据操作
Adding a new statistical information will determine the position to insert the data according to the current time. If the data position changes, the data will be sent to the left. If there is no movement or after the movement is completed, Custom data operations on the last number
(继承自 LogStatisticsBaseT。)
受保护的方法StatisticsCustomAction(FuncT, T, DateTime)
新增一个统计信息,将会根据当前的时间来决定插入数据位置,如果数据位置发生了变化,则数据向左发送移动。如果没有移动或是移动完成后,最后一个数进行自定义的数据操作
Adding a new statistical information will determine the position to insert the data according to the current time. If the data position changes, the data will be sent to the left. If there is no movement or after the movement is completed, Custom data operations on the last number
(继承自 LogStatisticsBaseT。)
公共方法ToString (重写 ObjectToString.)
Top
字段
扩展方法
  名称说明
公共扩展器方法ToJsonString
获取当前对象的JSON格式表示的字符串。
Gets the string represented by the JSON format of the current object.
(由 HslExtension 定义。)
Top
示例
我们来举个例子:我有个方法,AAA需要记录一下连续60天的调用次数信息
简单的记录调用次数
/// <summary>
/// 定义一个缓存60天统计的信息内容,假设我们要统计最近60天内一个方法的调用次数<br />
/// Define a cache for 60 days of statistical information content, suppose we want to count the number of calls to a method in the last 60 days
/// </summary>
public LogStatistics logStatistics = new LogStatistics( GenerateMode.ByEveryDay, 60 );

/// <summary>
/// 假设这个方法就是我们需要统计的方法,我们统计最近的连续30天的使用次数情况<br />
/// Assuming that this method is the method we need to count, we count the number of uses for the most recent 30 consecutive days
/// </summary>
public void Example( )
{
    logStatistics.StatisticsAdd( );

    // 下面执行这个方法真正执行的内容

    // 如果你用来统计产量信息也是可以的
    logStatistics.StatisticsAdd( 10 ); // 这样可以一次增加10个产量
}

// 然后你就可以在其他的任何地方,其他线程里获取到当前的最新的long数组
public void AAA( )
{
    long[] data = logStatistics.GetStatisticsSnapshot( );  // 可以用于显示,然后监视系统的基本情况 返回30个数组长度的long[]

    // 当然我也可以获取指定日期的调用次数
    long[] data2 = logStatistics.GetStatisticsSnapshotByTime( new DateTime( 2020, 12, 10 ), new DateTime( 2020, 12, 19 ) );
    // 这样data2是10个长度的数据
}
因为这个数据是保存在内存里的,程序重新运行就丢失了,如果希望让这个数据一直在程序的话,在软件退出的时候需要存储文件,在软件启动的时候,加载文件数据
存储与加载
// 如果需要对数据进行保存
logStatistics.SaveToFile( "D:\\123.txt" );

// 当你系统启动的是,需要加载旧的数据信息
logStatistics.LoadFromFile( "D:\\123.txt" );
参见