[Enterprise Library for. NET Framework 2.0] custom log path or log file name, enterpriselibrary

Source: Internet
Author: User

[Enterprise Library for. NET Framework 2.0] custom log path or log file name, enterpriselibrary

Sometimes, logs are classified by time, for example, "20140821 \ trace. "log", configured by tools in the Enterprise Library, only the log file name can be defined. You can use the code to modify the FlatFileTraceListenerData implementation or Custom Trace Listener method,

The following code modifies FlatFileTraceListenerData:

        public static string GetTraceLogPath(string listenersName)        {            string _tracePath = string.Empty;            if (!string.IsNullOrEmpty(listenersName))            {                Configuration _etlConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);                LoggingSettings _loggingSettings = (LoggingSettings)_etlConfig.GetSection(LoggingSettings.SectionName);                FlatFileTraceListenerData _listeners = _loggingSettings.TraceListeners.Get(listenersName) as FlatFileTraceListenerData;                if (_listeners != null)                {                    _tracePath = _listeners.FileName;                }            }            return _tracePath;        }        public static void SetTraceLogPath(string listenersName, string fileName)        {            if (!string.IsNullOrEmpty(listenersName) && !string.IsNullOrEmpty(fileName))            {                Configuration _etlConfig = ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.None);                LoggingSettings _loggingSettings = (LoggingSettings)_etlConfig.GetSection(LoggingSettings.SectionName);                FlatFileTraceListenerData _listeners = _loggingSettings.TraceListeners.Get(listenersName) as FlatFileTraceListenerData;                if (_listeners != null)                {                    _listeners.FileName = fileName;                    _etlConfig.Save();                }            }        }

Test code:

Try {string _ listenName = "FlatFile TraceListener"; SetTraceLogPath (_ listenName, string. format (@ "{0}/trace. log ", DateTime. now. toString ("yyyyMMdd"); LogEntry log = new LogEntry (); log. categories. add ("Warning"); log. title = "test"; log. message = "log Content"; Logger. write (log); LogEntry log2 = new LogEntry (); log2.Categories. add ("Warning"); log2.Title = "Test 2"; log2.Message = "log Content 2"; Logger. write (log2); Console. writeLine (GetTraceLogPath (_ listenName);} catch (Exception ex) {Console. writeLine (ex. message);} finally {Console. readLine ();}

Test results:

Hope to help


How to configure a log file for a project

You can create a log file and make it contain diagnostic information related to interoperability, program loading, and network. You can enable logging by setting the registry key. First, set a registry key to enable regular logging, and then set the registry key for the required logging components and options.

You can set the registry key using the following methods:

Use the Remote Registry Editor in Visual Studio.

In. NET Compact Framework 2.0 Service Pack 1, use the logging option in the remote Performance Monitor. For more information about remote performance monitoring, see how to monitor performance at runtime.

In. NET Compact Framework 3.5, you can use the logging tool NetCFLogging.exe, which provides a simple graphical user interface for enabling and disabling logging. This tool is included in Power Toys for. NET Compact Framework. For more information, see Power Toys for. NET Compact Framework.

Use the Registry and RegistryKey classes. the. NET Compact Framework 2.0 and later versions support these classes.

The following table summarizes these log files.

Logging Component

Log File Content

Interoperability

Records COM interoperability calls. Provides information about platform calling and sending.

Error

Records all unprocessed and local exceptions. Record errors to log files and OutputDebugString. A log file is created for each Assembly located in the current path and applied to the current session. The log file will be overwritten after the first unhandled exception or local exception occurs.

Load programs

Record information about program loading. The file header contains the following information:

Application name.

Process ID (provided by Windows Embedded CE ).

The local date and time when the log file was created. The format is not global, but regional-specific.

. NET Compact Framework version, for example, 2.0.5021.00.

Platform-related information, such as Windows Embedded CE v5.0.1400 (CEPC) WinCE5x86 debug Dev i386 IJITv2.
The file provides the following information:

Force status (compatibility mode ).

The trust level specified for the module when the module is loaded.

Failed to parse the method.

Failed to parse the type.

An error occurred while searching for or loading the assembly or module.

Assembly loaded successfully.

The metadata version is invalid.

An error occurred while searching for the platform to call the DLL.

An error occurred while searching for functions in the platform Call DLL.

Policy file name, or the fact that the file is missing.

Major Errors During policy file processing.

Managed Assembly policy-based redirection.
You can also include information about global assembly caching.

Network

Record network traffic. The network log file is a binary file. If no. NET Compact Framework Log Viewer Logviewer.exe is available, the file cannot be accessed. In. NET Compact Framework 3.5 and later versions, the Log Viewer is included in Power Toys for. NET Compact Framework. For more information, see Power Toys for. NET Compact Framework.
Because network logging occurs on the Windows Socket Layer, the log file only contains network packet information. This includes data sent over the network, some of which may be sensitive data and therefore need to be encrypted.

Terminator

Records the class names of objects not released before the Garbage Collector discards them .. NET Compact Framework 3... the remaining full text>

Crystal reports for net framework 20 (X86), this software cannot be uninstalled, and the file path does not

In the registration, you can find and delete it.

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.