一直在用log4net来记录日志,但每次都是把之前写好的配置文件拷贝一份稍加修改,按说这样也没什么。但每次都看VS提示一票找不到框架信息,搞的我排错都很困难,很不爽,于是尝试上网搜一个架构文件,但下来一看,写的很简单,大不到我的需求,于是自己就写一个,并加入了一些约束条件、候选值、默认值什么的,这回可以像.net里的智能提示一样来操作log4net的配置。
类似如下的额引用,那么配置文件里的一些元素就可以有自动提示完成的功能了。
<log4net debug="false" xmlns="dxz:log4net" xmlns:l="dxz:log4net">
</log4net>
方便了很多,下面贴出来代码,拷贝下面的代码保存为log4net.xsd拷贝到 C:/Program Files/Microsoft Visual Studio 8/Xml/Schemas下,按照上面的引入方法就可以实现想编辑web.comfig或App.config文件一样有自动提示的功能,很好用的。
类似如下的额引用,那么配置文件里的一些元素就可以有自动提示完成的功能了。
<log4net debug="false" xmlns="dxz:log4net" xmlns:l="dxz:log4net">
</log4net>
方便了很多,下面贴出来代码,拷贝下面的代码保存为log4net.xsd拷贝到 C:/Program Files/Microsoft Visual Studio 8/Xml/Schemas下,按照上面的引入方法就可以实现想编辑web.comfig或App.config文件一样有自动提示的功能,很好用的。
- <?xml version="1.0" encoding="gb2312"?>
- <!--
- 作者:dxzhan
- Email:zhandx@163.com
- QQ:147977032
- 修改时间:2008-12-09
- 授权:这是一个log4net的架构文件,您可以任意使用和散播此文件的副本,同时您因为使用此文件造成的任何后果由您自己负责。
- 您使用此架构文件的前提是必须保留此授权。
- 任何有在此基础上进行改进的地方使用人有义务知会作者共同进步。
- 使用说明:将此文件拷贝到X:/Program Files/Microsoft Visual Studio 8/Xml/Schemas下
- 在log4net配置文件里加入类似如下命名空间引入
- <log4net debug="false" xmlns="dxz:log4net" xmlns:l="dxz:log4net">
- </log4net>
- 即可享受像使用VS自带的配置文件一样的元素属性自动提示、候选值、默认值等功能。
- -->
- <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="dxz:log4net" xmlns="dxz:log4net" elementFormDefault="qualified">
- <xs:element name="level">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value" use="required">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="OFF" />
- <xs:enumeration value="FATAL" />
- <xs:enumeration value="ERROR" />
- <xs:enumeration value="WARN" />
- <xs:enumeration value="INFO" />
- <xs:enumeration value="DEBUG" />
- <xs:enumeration value="ALL" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="appender-ref">
- <xs:complexType>
- <xs:attribute name="ref" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="bufferSize">
- <xs:complexType>
- <xs:attribute name="value" type="xs:decimal" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="connectionType">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="System.Data.OracleClient.OracleConnection, System.Data.OracleClient, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
- <xs:enumeration value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
- <xs:enumeration value="IBM.Data.DB2.DB2Connection,IBM.Data.DB2, Version=8.1.2.1" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="connectionString">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value" use="required">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="data source=[mydatabase];User ID=[user];Password=[password]" />
- <xs:enumeration value="data source=[database server];initial catalog=[database name];integrated security=false;persist security info=True;User ID=[user];Password=[password]" />
- <xs:enumeration value="server=127.0.0.1;database=dbuser;user Id=username;password=password;persist security info=true" />
- <xs:enumeration value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/log/access.mdb;User Id=;Password=;" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="commandText">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
- <xs:enumeration value="INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date, @thread, @log_level, @logger, @message)" />
- <xs:enumeration value="INSERT INTO Log (Datetime,Thread,Log_Level,Logger,Message) VALUES (:log_date, :thread, :log_level, :logger, :message)" />
- <xs:enumeration value="INSERT INTO myschema.Log (Date,Thread,Level,Logger,Message,Exception) VALUES (@log_date,@thread,@log_level,@logger,@message,@exception)" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="parameter">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="parameterName">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="dbType">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value" use="required">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="DateTime" />
- <xs:enumeration value="String" />
- <xs:enumeration value="Boolean" />
- <xs:enumeration value="Byte" />
- <xs:enumeration value="Decimal" />
- <xs:enumeration value="Double" />
- <xs:enumeration value="Int16" />
- <xs:enumeration value="Int32" />
- <xs:enumeration value="Int64" />
- <xs:enumeration value="Binary" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element minOccurs="0" name="size">
- <xs:complexType>
- <xs:attribute name="value" type="xs:decimal" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element ref="layout" />
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="layout">
- <xs:complexType>
- <xs:sequence minOccurs="0">
- <xs:choice maxOccurs="unbounded">
- <xs:element name="conversionPattern">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="%date %newline %message %newline %-20file %-5line %newline" />
- <xs:enumeration value="%date - %message %newline" />
- <xs:enumeration value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="param">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="name">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="Header" />
- <xs:enumeration value="Footer" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- <xs:attribute name="value">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="------------------------------------------[Header]-----------------------------------------" />
- <xs:enumeration value="------------------------------------------[Footer]-----------------------------------------" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- </xs:choice>
- </xs:sequence>
- <xs:attribute name="type" type="xs:string" use="optional" default="log4net.Layout.PatternLayout" />
- </xs:complexType>
- </xs:element>
- <xs:element name="mapping">
- <xs:complexType>
- <xs:sequence>
- <xs:choice>
- <xs:element ref="level" />
- <xs:element minOccurs="0" name="foreColor">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="backColor">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element minOccurs="0" name="attributes">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- </xs:choice>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element name="file">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value" use="required">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="log/Error.log" />
- <xs:enumeration value="/log/${TMP}/Error.log" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="appendToFile">
- <xs:complexType>
- <xs:attribute name="value" type="xs:boolean" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="rollingStyle">
- <xs:complexType>
- <xs:simpleContent>
- <xs:extension base="xs:string">
- <xs:attribute name="value">
- <xs:simpleType>
- <xs:restriction base="xs:string">
- <xs:enumeration value="Once" />
- <xs:enumeration value="Size" />
- <xs:enumeration value="Date" />
- <xs:enumeration value="Composite" />
- </xs:restriction>
- </xs:simpleType>
- </xs:attribute>
- </xs:extension>
- </xs:simpleContent>
- </xs:complexType>
- </xs:element>
- <xs:element name="maxSizeRollBackups">
- <xs:complexType>
- <xs:attribute name="value" type="xs:byte" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="maximumFileSize">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="filter">
- <xs:complexType>
- <xs:sequence>
- <xs:element maxOccurs="unbounded" name="param">
- <xs:complexType>
- <xs:attribute name="name" type="xs:string" use="required" />
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="type" type="xs:string" use="optional" default="log4net.Filter.LevelRangeFilter"/>
- </xs:complexType>
- </xs:element>
- <xs:element name="lossy">
- <xs:complexType>
- <xs:attribute name="value" type="xs:boolean" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="evaluator">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="threshold">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="ERROR" />
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="type" type="xs:string" use="optional" default="log4net.Core.LevelEvaluator" />
- </xs:complexType>
- </xs:element>
- <xs:element name="target">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="applicationName">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="encoding">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="unicodeFFFE" />
- </xs:complexType>
- </xs:element>
- <xs:element name="lockingModel">
- <xs:complexType>
- <xs:attribute name="type" type="xs:string" use="optional" default="log4net.Appender.FileAppender+MinimalLock" />
- </xs:complexType>
- </xs:element>
- <xs:element name="threshold">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="true" />
- </xs:complexType>
- </xs:element>
- <xs:element name="onlyFixPartialEventData">
- <xs:complexType>
- <xs:attribute name="value" type="xs:boolean" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="server">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="SQUARE" />
- </xs:complexType>
- </xs:element>
- <xs:element name="recipient">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="nicko" />
- </xs:complexType>
- </xs:element>
- <xs:element name="sink">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="tcp://localhost:8085/LoggingSink" />
- </xs:complexType>
- </xs:element>
- <xs:element name="staticLogFileName">
- <xs:complexType>
- <xs:attribute name="value" type="xs:boolean" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="datePattern">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="yyyyMMdd-HHmm" />
- </xs:complexType>
- </xs:element>
- <xs:element name="to">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="to@domain.com" />
- </xs:complexType>
- </xs:element>
- <xs:element name="from">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="from@domain.com" />
- </xs:complexType>
- </xs:element>
- <xs:element name="subject">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="test logging message" />
- </xs:complexType>
- </xs:element>
- <xs:element name="smtpHost">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="SMTPServer.domain.com" />
- </xs:complexType>
- </xs:element>
- <xs:element name="pickupDir">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="C:/SmtpPickup" />
- </xs:complexType>
- </xs:element>
- <xs:element name="localPort">
- <xs:complexType>
- <xs:attribute name="value" type="xs:decimal" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="remoteAddress">
- <xs:complexType>
- <xs:attribute name="value" type="xs:string" use="optional" default="127.0.0.1" />
- </xs:complexType>
- </xs:element>
- <xs:element name="remotePort">
- <xs:complexType>
- <xs:attribute name="value" type="xs:decimal" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="log4net">
- <xs:complexType>
- <xs:sequence>
- <xs:element maxOccurs="unbounded" name="appender">
- <xs:complexType>
- <xs:sequence>
- <xs:choice maxOccurs="unbounded">
- <xs:element ref="bufferSize" />
- <xs:element ref="connectionType" />
- <xs:element ref="connectionString" />
- <xs:element ref="commandText" />
- <xs:element ref="parameter" maxOccurs="unbounded" />
- <xs:element ref="mapping" maxOccurs="unbounded" />
- <xs:element ref="file" />
- <xs:element ref="appendToFile" />
- <xs:element ref="rollingStyle" />
- <xs:element ref="maxSizeRollBackups" />
- <xs:element ref="maximumFileSize" />
- <xs:element ref="layout" />
- <xs:element ref="filter" />
- <xs:element ref="appender-ref" />
- <xs:element ref="lossy" />
- <xs:element ref="evaluator" />
- <xs:element ref="target" />
- <xs:element ref="applicationName" />
- <xs:element ref="encoding" />
- <xs:element ref="lockingModel" />
- <xs:element ref="threshold" />
- <xs:element ref="onlyFixPartialEventData" />
- <xs:element ref="server" />
- <xs:element ref="recipient" />
- <xs:element ref="sink" />
- <xs:element ref="staticLogFileName" />
- <xs:element ref="datePattern" />
- <xs:element ref="to" />
- <xs:element ref="from" />
- <xs:element ref="subject" />
- <xs:element ref="smtpHost" />
- <xs:element ref="pickupDir" />
- <xs:element ref="localPort" />
- <xs:element ref="remoteAddress" />
- <xs:element ref="remotePort" />
- </xs:choice>
- </xs:sequence>
- <xs:attribute name="name" type="xs:string" use="required" />
- <xs:attribute name="type" type="xs:string" use="required" />
- </xs:complexType>
- </xs:element>
- <xs:element name="root" maxOccurs="1">
- <xs:complexType>
- <xs:sequence>
- <xs:element ref="level" />
- <xs:element ref="appender-ref" maxOccurs="unbounded" />
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- <xs:element maxOccurs="unbounded" name="logger">
- <xs:complexType>
- <xs:sequence>
- <xs:element ref="level" />
- <xs:element minOccurs="0" maxOccurs="unbounded" ref="appender-ref" />
- </xs:sequence>
- <xs:attribute name="name" type="xs:string" use="required" />
- <xs:attribute name="additivity" type="xs:boolean" use="optional" />
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="debug" type="xs:boolean" use="required" />
- </xs:complexType>
- </xs:element>
- </xs:schema>