Lightweight. NET Object Search Service and AOP development framework Netop. Core source code explanation (5) -- others, aopnetop. core

Source: Internet
Author: User
Tags log4net

Lightweight. NET Object Search Service and AOP development framework Netop. Core source code explanation (5) -- others, aopnetop. core

Netop. Core mainly provides factory-like services and AOP services. Of course, there are other small services:

1. Dialog Context Netop. Core. Context. SessionContext
This dialog context can be used in desktop programs and ASP. NET programs, and SetData and GetData can be used to transmit data in the context. Methods:
Public static bool IsWeb ()
Public static string GetAppMapPath (string path)
Public static object GetData (string key)
Public static object GetData (string key, bool isToSession)
Public static void SetData (string key, object value)
Public static void SetData (string key, object value, bool isToSession)
Public static void Remove (string key)

Ii. Buffering
The buffer interfaces ICache, ILocalCache (local buffer), and Netop are defined. core. cache. microsoftEnterpriseLibraryCache is packaged by Microsoft. practices. enterpriseLibrary. caching is a class that implements the ILocalCache interface. Of course, you can also make a class that encapsulates MemCached to implement the ICache interface, so you can share it later.
The local buffer service is called through Netop. Core. Cache. AppMemoryCache. Of course, the configuration file needs to be configured:
Configuration related to Microsoft. Practices. EnterpriseLibrary. Caching is as follows:

<ConfigSections>
<Section name = "cachingConfiguration" type = "Microsoft. Practices. EnterpriseLibrary. Caching. Configuration. CacheManagerSettings, Microsoft. Practices. EnterpriseLibrary. Caching"/>
<Section name = "Netop. Application" type = "Netop. Core. Configuration. ConfigurationHandler, Netop. Core"/>
<Section name = "log4net" type = "log4net. Config. Log4NetConfigurationSectionHandler, log4net"/>
</ConfigSections>

<CachingConfiguration defaultCacheManager = "Default Cache Manager">
<BackingStores>
<Add name = "inMemory" type = "Microsoft. Practices. EnterpriseLibrary. Caching. BackingStoreImplementations. NullBackingStore, Microsoft. Practices. EnterpriseLibrary. Caching"/>
</BackingStores>
<CacheManagers>
<Add name = "Default Cache Manager"
Type = "Microsoft. Practices. EnterpriseLibrary. Caching. CacheManager, Microsoft. Practices. EnterpriseLibrary. Caching"
ExpirationPollFrequencyInSeconds = "60"
MaximumElementsInCacheBeforeScavenging = "1000"
NumberToRemoveWhenScavenging = "10"
BackingStoreName = "inMemory"/>
</CacheManagers>
</CachingConfiguration>

Configuration Under the <Netop. Application> node:

<Application. Cache>
<Provider> Netop. Core. Cache. MicrosoftEnterpriseLibraryCache, Netop. Core </Provider>
<ApplicationLog> Application. Log </ApplicationLog>

<ExpirationPolicy. IsSet> 1 </ExpirationPolicy. IsSet>
<ExpirationPolicy. Expiration> 60 </ExpirationPolicy. Expiration>
<ExpirationPolicy. TypeFullName> Microsoft. Practices. EnterpriseLibrary. Caching. Expirations. SlidingTime, Microsoft. Practices. EnterpriseLibrary. Caching </ExpirationPolicy. TypeFullName>
</Application. Cache>

After setting these configurations, you can use the AppMemoryCache method:

Public static void AddCacheData (string key, object data)
Public static void AddCacheData (string key, object data, Priority priority)
Public static void AddCacheDataForEver (string key, object data)
Public static void AddCacheDataForFileDependency (string key, object data, Priority priority, string fileName)
Public static void AddDataForAbsoluteTime (string key, object data, Priority priority, TimeSpan timeFromNow)
Public static void AddDataForAbsoluteTime (string key, object data, Priority priority, System. DateTime absoluteTime)
Public static void AddDataForSlidingTime (string key, object data, Priority priority, TimeSpan slidingExpiration)
Public static void AddDataForSlidingTime (string key, object data, Priority priority, TimeSpan slidingExpiration, System. DateTime originalTimeStamp)
Public static object GetCacheData (string key)
Public static void RemoveCacheData (string key)
Public static bool Contains (string key)
Public static int Count

Iii. Logs
Netop. Core. Log. Log4Net is a Log4Net packaging class that implements the Netop. Core. Log. ILog interface. The ILog interface is:
Public interface ILog
{
Void Debug (object message );
Void Write (object message );
Void Write (object message, LogInfoType logInfoType );
Void Write (object message, Exception exception );
Void Write (object message, Exception exception, LogInfoType logInfoType );
}
Netop. core. log. logManager is a factory class that uses logs. The most important processing is how to extract the encrypted ConnectionString to Log4Net When configuring logs for Log4Net databases, for details, see the GetLog4NetLogger method and related configuration code.

The configuration related to Log4Net is as follows:
<ConfigSections>
<Section name = "Netop. Application" type = "Netop. Core. Configuration. ConfigurationHandler, Netop. Core"/>
<Section name = "log4net" type = "log4net. Config. Log4NetConfigurationSectionHandler, log4net"/>
</ConfigSections>
In addition, configure the <log4net> vertex, for example:
<Log4net>
<Logger name = "Log">
<Level value = "ERROR"/>
<Appender-ref = "LogFile"/>
</Logger>
<Appender name = "LogFile" type = "log4net. Appender. FileAppender">
<Param name = "File" value = "Log/log-file.txt"/>
<Param name = "AppendToFile" value = "true"/>
<Layout type = "log4net. Layout. PatternLayout">
<Param name = "ConversionPattern" value = "% d [% t] %-5 p [% c] % m % n"/>
</Layout>
</Appender>
</Log4net>

What about the configuration in Netop. Application? If you want to configure another log, you can add a configuration similar to this in Netop. Application (of course, please give XXXXXX and YYYYYY a good name), such:
<XXXXXX>
<LogCategory> Netop. Core. Log. Log4Net, Netop. Core </LogCategory>
<LogParameter> YYYYYY </LogParameter>
</XXXXXX>
One configuration of my own system is (of course there are multiple table-style log configurations ):
<Application. Log>
<LogCategory> Netop. Core. Log. Log4Net, Netop. Core </LogCategory>
<LogParameter> Log </LogParameter>
</Application. Log>
Of course, you need to configure the corresponding Log in log4net. (refer to the related Log4Net documents ), the Log name in <LogParameter> Log </LogParameter> above is the Log name of <logger name = "Log"> above, which must be associated.

Then the program can be called:
Netop. Core. Log. ILog log = Netop. Core. Log. LogManager. GetLogger ("Application. Log ");
Log. Debug ("...");

By the way
<Application. Cache>
...
<ApplicationLog> Application. Log </ApplicationLog>
...
</Application. Cache>
<ApplicationLog> Application. log </ApplicationLog> indicates the Application. log configuration in Netop. core. cache. microsoftEnterpriseLibraryCache, Netop. you can record related logs based on Configurations in Core.


Other small services, such as verification codes, are easy to use.

Lightweight. NET Object Search Service and AOP development framework source code Netop. Core3.5: http://download.csdn.NET/detail/tom_cat_xie_jxdy/9837303

Lightweight. NET Object Search Service and AOP development framework test source code: http://download.csdn.Net/detail/tom_cat_xie_jxdy/9837278

Netop. Core -- lightweight. NET object Lookup service and AOP development framework documentation: http://download.csdn.net/detail/tom_cat_xie_jxdy/9838212




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.