comparison Logging/FileLogger.cs @ 0:961030992bd2

Initial commit of IBBoard libraries
author IBBoard <dev@ibboard.co.uk>
date Fri, 19 Dec 2008 11:13:48 +0000
parents
children 0352fa33ee8f
comparison
equal deleted inserted replaced
-1:000000000000 0:961030992bd2
1 using System;
2 using System.IO;
3
4 namespace IBBoard.Logging
5 {
6 public abstract class FileLogger : Logger
7 {
8 public FileLogger() : this(CreateDefaultLogFileStream())
9 {
10 }
11
12 public FileLogger(string path) : this(CreateLogFileStream(path))
13 {
14 }
15
16 public FileLogger(FileInfo file) : this(CreateLogFileStream(file))
17 {
18 }
19
20 public FileLogger(FileStream stream) : base(stream)
21 {
22 }
23
24 public static string MakeDefaultLogFilePath()
25 {
26 return MakeLogFilePath(Constants.UserDataPath);
27 }
28
29 public static string MakeLogFilePath(string path)
30 {
31 return path.TrimEnd(IBBoard.Constants.DirectoryChar) + IBBoard.Constants.DirectoryChar + "logs" + IBBoard.Constants.DirectoryChar + String.Format("{0:yyyy-MM-dd-HHmmss}", DateTime.Now)+".log";
32 }
33
34 public static FileStream CreateDefaultLogFileStream()
35 {
36 return CreateLogFileStream(MakeDefaultLogFilePath());
37 }
38
39 public static FileStream CreateLogFileStream(string path)
40 {
41 return CreateLogFileStream(new FileInfo(path));
42 }
43
44 public static FileStream CreateLogFileStream(FileInfo file)
45 {
46 if (!file.Directory.Exists)
47 {
48 file.Directory.Create();
49 }
50
51 return new FileStream(file.FullName, FileMode.OpenOrCreate, FileAccess.Write);
52 }
53 }
54 }