Repository navigation
Expand file tree
/
Copy pathEnableLogFileCommand.cs
More file actions
88 lines (75 loc) · 2.34 KB
/
Copy pathEnableLogFileCommand.cs
File metadata and controls
88 lines (75 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global
namespace PSLogging.Commands
{
using System.Management.Automation;
[Cmdlet(VerbsLifecycle.Enable, "LogFile")]
public class EnableLogFileCommand : PSCmdlet
{
private ScriptBlock errorCallback;
private LogFile inputObject;
private string path;
private StreamType streams = StreamType.All;
private string dateTimeFormat = "r";
#region Parameters
[Parameter(ParameterSetName = "AttachExisting",
Mandatory = true,
Position = 0,
ValueFromPipeline = true)]
public LogFile InputObject
{
get { return inputObject; }
set { inputObject = value; }
}
[Parameter(ParameterSetName = "New")]
public ScriptBlock OnError
{
get { return errorCallback; }
set { errorCallback = value; }
}
[Parameter(Mandatory = true,
Position = 0,
ParameterSetName = "New")]
public string Path
{
get { return path; }
set
{
path = GetUnresolvedProviderPathFromPSPath(value);
}
}
[Parameter(ParameterSetName = "New")]
public StreamType StreamType
{
get { return streams; }
set { streams = value; }
}
[Parameter(ParameterSetName = "New")]
public string DateTimeFormat
{
get { return dateTimeFormat; }
set { dateTimeFormat = value; }
}
#endregion
protected override void EndProcessing()
{
LogFile logFile;
if (ParameterSetName == "New")
{
logFile = new LogFile(path, streams, errorCallback, dateTimeFormat);
WriteObject(logFile);
}
else
{
logFile = inputObject;
}
HostIOInterceptor.Instance.AttachToHost(Host);
HostIOInterceptor.Instance.AddSubscriber(logFile);
}
} // End AddLogFileCommand class
}
// ReSharper restore MemberCanBePrivate.Global
// ReSharper restore UnusedAutoPropertyAccessor.Global
// ReSharper restore UnusedMember.Global