-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathEnableApplicationInsightsCommand.cs
More file actions
68 lines (57 loc) · 1.9 KB
/
EnableApplicationInsightsCommand.cs
File metadata and controls
68 lines (57 loc) · 1.9 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
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global
namespace PSLogging.Commands
{
using System.Management.Automation;
[Cmdlet(VerbsLifecycle.Enable, "ApplicationInsights")]
public class EnableApplicationInsightsCommand : PSCmdlet
{
private ApplicationInsightsOutputSubscriber inputObject;
private string key;
private string dateTimeFormat = "r";
#region Parameters
[Parameter(ParameterSetName = "AttachExisting",
Mandatory = true,
Position = 0,
ValueFromPipeline = true)]
public ApplicationInsightsOutputSubscriber InputObject
{
get { return inputObject; }
set { inputObject = value; }
}
[Parameter(Mandatory = true,
Position = 0,
ParameterSetName = "New")]
public string Key
{
get { return key; }
set { key = value; }
}
[Parameter(ParameterSetName = "New")]
public string DateTimeFormat
{
get { return dateTimeFormat; }
set { dateTimeFormat = value; }
}
#endregion
protected override void EndProcessing()
{
ApplicationInsightsOutputSubscriber subscriber;
if (ParameterSetName == "New")
{
subscriber = new ApplicationInsightsOutputSubscriber(key, dateTimeFormat);
WriteObject(subscriber);
}
else
{
subscriber = inputObject;
}
HostIOInterceptor.Instance.AttachToHost(Host);
HostIOInterceptor.Instance.AddSubscriber(subscriber);
}
}
}
// ReSharper restore MemberCanBePrivate.Global
// ReSharper restore UnusedAutoPropertyAccessor.Global
// ReSharper restore UnusedMember.Global