log4net 修改日志输出格式的绝对文件路径为相对文件名
2013-04-21 20:02
477 查看
log4net-1.2.11 输出日志格式%file输出的是绝对文件路径,其实没有必要,只需要输出文件名即可。
修改源码:log4net-1.2.11\src\Layout\Pattern\FileLocationPatternConverter.cs
writer.Write(Path.GetFileName(loggingEvent.LocationInformation.FileName));
重新编译即可
修改源码:log4net-1.2.11\src\Layout\Pattern\FileLocationPatternConverter.cs
writer.Write(Path.GetFileName(loggingEvent.LocationInformation.FileName));
#region Apache License // // Licensed to the Apache Software Foundation (ASF) under one or more // contributor license agreements. See the NOTICE file distributed with // this work for additional information regarding copyright ownership. // The ASF licenses this file to you under the Apache License, Version 2.0 // (the "License"); you may not use this file except in compliance with // the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #endregion using System; using System.Text; using System.IO; using log4net.Core; namespace log4net.Layout.Pattern { /// <summary> /// Writes the caller location file name to the output /// </summary> /// <remarks> /// <para> /// Writes the value of the <see cref="LocationInfo.FileName"/> for /// the event to the output writer. /// </para> /// </remarks> /// <author>Nicko Cadell</author> internal sealed class FileLocationPatternConverter : PatternLayoutConverter { /// <summary> /// Write the caller location file name to the output /// </summary> /// <param name="writer"><see cref="TextWriter" /> that will receive the formatted result.</param> /// <param name="loggingEvent">the event being logged</param> /// <remarks> /// <para> /// Writes the value of the <see cref="LocationInfo.FileName"/> for /// the <paramref name="loggingEvent"/> to the output <paramref name="writer"/>. /// </para> /// </remarks> override protected void Convert(TextWriter writer, LoggingEvent loggingEvent) { writer.Write(Path.GetFileName(loggingEvent.LocationInformation.FileName)); } } }
重新编译即可
相关文章推荐
- 使用log4net将日志文件输出替csv格式
- Log4j日志文件输出为相对路径的解决方法
- 修改Keepalived配置文件位置以及重定向Keepalived日志的输出路径
- 修改Keepalived配置文件位置以及重定向Keepalived日志的输出路径
- ROSE建模文件如何把绝对路径修改成相对路径
- 根据文件名取文件【含相对路径和绝对路径处理】
- log4j按级别分类输出日志到相对路径日志文件
- Log4j日志文件输出为相对路径的解决方法
- java 从键盘输入一个关键字,在 D:盘查找文件,如果文件名中包含该关键字,则输出这个文件的绝对路径,如果都没有找到,则输出找不到相关信息。
- 使用log4net将日志文件输出为csv格式
- 在运行时修改log4Net的日志文件路径
- log4j中日志输出文件指定相对路径的方法
- Log4j日志文件输出为相对路径的解决方法
- 织梦DEDECMS更换目录后需要修改的内容绝对路径与相对路径问题
- 文件路径(相对、绝对路)、项目设置中的使用
- 【转】VC中获取文件的相对路径和绝对路径
- log4j中配置日志文件相对路径方法
- log4j 设置日志输出文件的路径
- jar包中读取文件系统绝对路径,相对路径,以及jar包内部路径的写法
- 文件的相对路径和绝对路径以及根相对路径