.NET abnormal publisher development (2)

zhaozj2021-02-16  55

The following is configured with a class to configure the publisher, such as obtaining the position of the above three files and setting the relevant configuration:

///

/// ExceptionSetting summary description.

///

Public class exceptionSetting

{

///

/// Get folder for exception processing

///

Public Static String FilePath

{

get

{

String fullpath;

IF (Appconfig.GetAppSetting ("ExceptionPath")! = NULL)

{

FullPath = Appconfig.getAppSetting ("ExceptionPath");

While (fullpath.startswith ("//"))

{

Fullpath = FullPath.Remove (0, 1);

}

}

Else

{

Fullpath = path.getdirectoryName (path.getfullpath ("temp.xml"));

}

Fullpath = path.getFullPath (Fullpath);

Fullpath = FullPath "//";

IF (! Directory.exists (Path.GetDirectoryName (Fullpath)))

{

Directory.createdIRectory (path.getdirectoryName);

}

Return Fullpath;

}

}

///

/// Get or set the string of folders for exception processing

///

Public Static String FilePathSettingString

{

get

{

Return Appconfig.GetAppSetting ("ExceptionPath");

}

set

{

Appconfig.saveAppSetting ("ExceptionPath", Value;

}

}

///

/// Get or set the system exception record type, default to use XML file record

///

Public Static CanuseExceptionLogType ExceptionLogType

{

get

{

String exceptionLogType = Appconfig.GetAppSetting ("exceptionLogType";

IF (ExceptionLogType.Tolower (). Trim () == canuseExceptionLogType.systemlog.toString (). TOLOWER ())

{

Return canuseExceptionLogType.systemlog;

}

ELSE IF (ExceptionLogType.tolower (). Trim () == canuseExceptionLogType.all.tostring (). TOLOWER ())

{

Return canuseExceptionLogType.all;

}

Else

Return canuseExceptionLogType.xmlfile;

}

set

{

Appconfig.saveAppSetting ("ExceptionLogType", value.tostring ());

}

}

}

The following category is to read and write three files used in the abnormal publisher:

///

A summary description of /// logaccess.

///

Public Class logaccess

{

///

/// Write an exception handling log

///

///

Public Static Void WriteLogfile (ExceptionLogdata DS)

{

DS.WRITEXML (ExceptionSetting.FilePath "ExceptionLog.xml");

}

///

/// read out an exception handling log

///

///

Public Static ExceptionLogdata Readlogfile ()

{

ExceptionLogData DS = New ExceptionLogdata ();

IF (! file.exists (exceptionsetting.filepath "exceptionlog.xml"))

{

DS.WRITEXML (ExceptionSetting.FilePath "ExceptionLog.xml");

}

Ds.clear ();

DS.Readxml (ExceptionSetting.FilePath "ExceptionLog.xml");

Return DS;

}

///

/// read the custom universal information

///

///

Public Static CustomOutMestageData getCustomOutmessage ()

{

CustomOutMessageData DS = New CustomOutMessageData ();

IF (! file.exists (exceptionSetting.filepath "customoutmessage.xml")))))

{

DS.WriteXML (ExceptionSetting.FilePath "CustomoutMessage.xml");

}

Ds.clear ();

DS.Readxml (ExceptionSetting.FilePath "CustomoutMessage.xml");

Return DS;

}

///

/// Write custom universal information

///

///

Public Static Void Savecustomoutmessage (CustomoutMessageData DS)

{

DS.WriteXML (ExceptionSetting.FilePath "CustomoutMessage.xml");

}

///

/// Get an exception handling definition information

///

/// Read the exception handling definition information

Public Static ExceptionDetAildata getExceptionDetail ()

{

ExceptionDetAildata ExceptionDetAilds = New ExceptionDetAildata ();

IF (! file.exists (exceptionSetting.filepath "exceptionList.xml"))

{

ExceptionDetAilds.writexml (ExceptionSetting.FilePath "ExceptionList.xml");

FileStream Fs = New FileStream (ExceptionSetting.FilePath "ExceptionList.xml", FileMode.Openorcreate, FileAccess.Readwrite;

Streamwriter W = New StreamWriter (FS);

W.BaseStream.seek (0, seekorigin.end);

w.write ("/ n / n ");

w.flush ();

W. close ();

}

ExceptionDetAilds.clear ();

ExceptionDetAilds.Readxml (ExceptionSetting.FilePath "ExceptionList.xml");

Return EXCEPTIONDETAILDS;

}

///

// / save an exception handling definition information

///

/// Abnormal processing definition information to be saved

Public Static Void SaveExceptionDetail (ExceptionDetAildata ExceptionDetAilds)

{

ExceptionDetAilds.writexml (ExceptionSetting.FilePath "ExceptionList.xml");

FileStream Fs = New FileStream (ExceptionSetting.FilePath "ExceptionList.xml", FileMode.Openorcreate, FileAccess.Readwrite;

Streamwriter W = New StreamWriter (FS);

W.BaseStream.seek (0, seekorigin.end);

w.write ("/ n / n "); w.flush ();

W. close ();

}

}

(Endlessly)

转载请注明原文地址:https://www.9cbs.com/read-24281.html

New Post(0)