Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: Auto Text complete application Pin
saman334-Jan-13 19:03
saman334-Jan-13 19:03 
GeneralRe: Auto Text complete application Pin
Sandeep Mewara4-Jan-13 19:43
mveSandeep Mewara4-Jan-13 19:43 
GeneralRe: Auto Text complete application Pin
saman335-Jan-13 2:12
saman335-Jan-13 2:12 
Questioncreating a browser plug in like quicktime or flash player or pdf reader or smiliar Pin
muharrem4-Jan-13 1:23
muharrem4-Jan-13 1:23 
AnswerRe: creating a browser plug in like quicktime or flash player or pdf reader or smiliar Pin
Pete O'Hanlon4-Jan-13 2:03
mvePete O'Hanlon4-Jan-13 2:03 
GeneralRe: creating a browser plug in like quicktime or flash player or pdf reader or smiliar Pin
muharrem4-Jan-13 10:13
muharrem4-Jan-13 10:13 
AnswerRe: creating a browser plug in like quicktime or flash player or pdf reader or smiliar Pin
Super Lloyd4-Jan-13 19:37
Super Lloyd4-Jan-13 19:37 
Questionlog4net on Windows 7 Pin
Simon_Whale4-Jan-13 0:10
Simon_Whale4-Jan-13 0:10 
Maybe I'm just having a blonde moment but

I am trying to convert a Winforms application from XP to Windows 7 which uses Log4Net.

C#
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
  </configSections>

  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="{0}.log"/>
      <appendToFile value="true"/>
      <rollingStyle value="Size"/>
      <maxSizeRollBackups value="5"/>
      <maximumFileSize value="100kb"/>
      <staticLogFileName value="true"/>
      <layout type="Oak.Common.Logger.MyPatternMatch">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline"/>
      </layout>
    </appender>
    <root>
      <level value="ALL"></level>
      <appender-ref ref="RollingLogFileAppender"/>
    </root>
  </log4net>


I dynamically create a log file location using the following code

C#
string Path = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)  + @"\Windows7Log4NetLogs\" + DateTime.Today.ToString("ddMMyyyy");
Logmanager.ChangeLogFile(Path);


Which creates the file successfully but when I try to send in a piece of text to the file nothing gets written and I am stumped I have tried different SpecialFolder options but it still doesn't write anything to the log file. Below is the code that I use for logging.

C#
public class Logmanager
{
    private static readonly Lazy<Logmanager> instance = new Lazy<Logmanager>(() => new Logmanager());

    private Logmanager() { }

    public static Logmanager Instance
    {
        get { return instance.Value; }
    }

    public ILog Logger(string LoggerName)
    {
        return log4net.LogManager.GetLogger(LoggerName);
    }


    /// <summary>
    /// This allows you to specify the log file name.
    /// </summary>
    public static void ChangeLogFile(string filename)
    {
        log4net.Repository.ILoggerRepository RootRep;
        RootRep = LogManager.GetRepository(Assembly.GetCallingAssembly());

        XmlElement section = ConfigurationManager.GetSection("log4net") as XmlElement;
        XPathNavigator navigator = section.CreateNavigator();
        XPathNodeIterator nodes = navigator.Select("appender/file");

        foreach (XPathNavigator appender in nodes)
        {
            appender.MoveToAttribute("value", string.Empty);
            appender.SetValue(string.Format(appender.Value, filename));
        }

        IXmlRepositoryConfigurator xmlCon = RootRep as IXmlRepositoryConfigurator;
        xmlCon.Configure(section);
    }
}


EDIT:

I have also tried to write an ordinary text file to the same directory using a StreamWriter and that works, so I don't think that it is a permissions issue.

Anyone got any ideas or pointers for me.


Thanks
Simon
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch


modified 4-Jan-13 9:57am.

AnswerRe: log4net on Windows 7 Pin
Brisingr Aerowing4-Jan-13 9:15
professionalBrisingr Aerowing4-Jan-13 9:15 
AnswerRe: log4net on Windows 7 Pin
Brisingr Aerowing4-Jan-13 9:23
professionalBrisingr Aerowing4-Jan-13 9:23 
GeneralRe: log4net on Windows 7 Pin
jschell4-Jan-13 13:55
jschell4-Jan-13 13:55 
GeneralRe: log4net on Windows 7 Pin
Brisingr Aerowing4-Jan-13 13:59
professionalBrisingr Aerowing4-Jan-13 13:59 
GeneralRe: log4net on Windows 7 Pin
jschell6-Jan-13 4:44
jschell6-Jan-13 4:44 
GeneralRe: log4net on Windows 7 Pin
Simon_Whale5-Jan-13 13:04
Simon_Whale5-Jan-13 13:04 
GeneralRe: log4net on Windows 7 Pin
Brisingr Aerowing5-Jan-13 13:21
professionalBrisingr Aerowing5-Jan-13 13:21 
GeneralRe: log4net on Windows 7 Pin
Simon_Whale6-Jan-13 2:02
Simon_Whale6-Jan-13 2:02 
GeneralRe: log4net on Windows 7 Pin
Brisingr Aerowing6-Jan-13 7:01
professionalBrisingr Aerowing6-Jan-13 7:01 
AnswerRe: log4net on Windows 7 Pin
jschell4-Jan-13 14:01
jschell4-Jan-13 14:01 
GeneralRe: log4net on Windows 7 Pin
Simon_Whale6-Jan-13 2:04
Simon_Whale6-Jan-13 2:04 
GeneralRe: log4net on Windows 7 Pin
jschell6-Jan-13 4:45
jschell6-Jan-13 4:45 
QuestionC# Equivalent of a Vlookup Pin
Member 97041533-Jan-13 22:00
Member 97041533-Jan-13 22:00 
AnswerRe: C# Equivalent of a Vlookup Pin
nainakarri4-Jan-13 0:55
nainakarri4-Jan-13 0:55 
GeneralRe: C# Equivalent of a Vlookup Pin
Member 97041534-Jan-13 1:38
Member 97041534-Jan-13 1:38 
GeneralRe: C# Equivalent of a Vlookup Pin
nainakarri4-Jan-13 20:22
nainakarri4-Jan-13 20:22 
QuestionXML Mapping to CSV Pin
RickSharp3-Jan-13 11:32
RickSharp3-Jan-13 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.