Skip to content

Commit 4b446e8

Browse files
authored
Merge pull request #29 from stackify/feature/SF-6592
Configure appveyor to publish to myget
2 parents 869aa30 + 3a4879b commit 4b446e8

File tree

4 files changed

+201
-114
lines changed

4 files changed

+201
-114
lines changed

README.md

Lines changed: 139 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
##Stackify API for .NET
1+
# Stackify API for .NET
2+
3+
[![Build status](https://ci.appveyor.com/api/projects/status/6suxse470ab4bdxl?svg=true)](https://ci.appveyor.com/project/jaredcnance/stackify-api-dotnet)
4+
[![NuGet](https://img.shields.io/nuget/v/StackifyLib.svg)](https://www.nuget.org/packages/StackifyLib/)
25

36
Library for Stackify users to integrate Stackify in to their projects. Provides support for sending errors, logs, and custom metrics to Stackify. Also some support for querying metric data back out of Stackify for use in external projects.
47

@@ -35,41 +38,52 @@ The packages for log4net, NLog and Elmah all depend on StackifyLib. StackifyLib
3538

3639
The following is required in your App.config or Web.config:
3740

38-
<appSettings>
39-
<add key="Stackify.ApiKey" value="YOUR API KEY HERE" />
40-
<add key="Stackify.AppName" value="YOUR APP NAME" />
41-
<add key="Stackify.Environment" value="OPTIONAL ENVIRONMENT NAME LIKE PROD, DEV" />
42-
</appSettings>
41+
```xml
42+
<appSettings>
43+
<add key="Stackify.ApiKey" value="YOUR API KEY HERE" />
44+
<add key="Stackify.AppName" value="YOUR APP NAME" />
45+
<add key="Stackify.Environment" value="OPTIONAL ENVIRONMENT NAME LIKE PROD, DEV" />
46+
</appSettings>
47+
```
4348

4449
Optionally, you can set the config settings on your machine's environment variables with the same configuration key and value.
4550
Example are executed in window's cmd as an admin:
51+
```
52+
setx Stackify.ApiKey "YOUR API KEY HERE" /m
53+
setx Stackify.Environment "MY ENVIRONMENT HERE" /m
54+
```
4655

47-
setx Stackify.ApiKey "YOUR API KEY HERE" /m
48-
setx Stackify.Environment "MY ENVIRONMENT HERE" /m
49-
5056
You can set the config settings in code like so which will override the appSettings configs as well.
5157

52-
StackifyLib.Logger.GlobalApiKey = "";
53-
StackifyLib.Logger.GlobalAppName = "";
54-
StackifyLib.Logger.GlobalEnvironment = "";
55-
58+
```
59+
StackifyLib.Logger.GlobalApiKey = "";
60+
StackifyLib.Logger.GlobalAppName = "";
61+
StackifyLib.Logger.GlobalEnvironment = "";
62+
```
63+
5664
By default the library will use the WebRequest.DefaultWebProxy. If you want to set a specific proxy server only for StackifyLib, you can do so in code OR via config.
5765

58-
<appSettings>
59-
<add key="Stackify.ProxyServer" value="http://test:[email protected]:8888/" />
60-
</appSettings>
61-
62-
StackifyLib.Utils.HttpClient.CustomWebProxy = new WebProxy();
66+
```xml
67+
<appSettings>
68+
<add key="Stackify.ProxyServer" value="http://test:[email protected]:8888/" />
69+
</appSettings>
70+
```
71+
72+
```csharp
73+
StackifyLib.Utils.HttpClient.CustomWebProxy = new WebProxy();
74+
```
6375

6476
If you are having problems you can get logging out of the framework by hooking in to its custom logging.
6577

66-
StackifyLib.Utils.StackifyAPILogger.LogEnabled = true;
67-
StackifyLib.Utils.StackifyAPILogger.OnLogMessage += StackifyAPILogger_OnLogMessage;
78+
```csharp
79+
StackifyLib.Utils.StackifyAPILogger.LogEnabled = true;
80+
StackifyLib.Utils.StackifyAPILogger.OnLogMessage += StackifyAPILogger_OnLogMessage;
6881

69-
static void StackifyAPILogger_OnLogMessage(string data)
70-
{
71-
Debug.WriteLine(data);
72-
}
82+
static void StackifyAPILogger_OnLogMessage(string data)
83+
{
84+
Debug.WriteLine(data);
85+
}
86+
```
7387

7488
Please note that Newtonsoft.Json is used by StackifyLib but is embedded as a resource to avoid version conflicts. Costura.Fody is being used to embed it. If you have any issues with Newtonsoft.Json as a result of using StackifyLib please contact Stackify support.
7589

@@ -86,27 +100,30 @@ PM> Install-Package NLog.Targets.Stackify
86100
```
87101

88102
Sample config:
89-
90-
<nlog>
103+
```xml
104+
<nlog>
91105
<extensions>
92-
<add assembly="NLog.Targets.Stackify"/>
106+
<add assembly="NLog.Targets.Stackify"/>
93107
</extensions>
94108
<targets>
95-
<target name="stackify" type="StackifyTarget" globalContextKeys="examplekey1,key2"
109+
<target name="stackify" type="StackifyTarget" globalContextKeys="examplekey1,key2"
96110
mappedContextKeys="" callContextKeys="" logMethodNames="true" />
97111
</targets>
98112
<rules>
99-
<logger name="*" writeTo="stackify" minlevel="Debug" />
113+
<logger name="*" writeTo="stackify" minlevel="Debug" />
100114
</rules>
101-
</nlog>
115+
</nlog>
116+
```
102117

103118
Logging custom objects is supported and will be searchable in Stackify's log viewer
104119

105-
static NLog.Logger nlog = NLog.LogManager.GetCurrentClassLogger();
106-
Dictionary<string, object> dictionary = new Dictionary<string, object>();
107-
dictionary["clientid"] = 1;
108-
dictionary["color"] = "red";
109-
nlog.Debug("Test message", dictionary);
120+
```csharp
121+
static NLog.Logger nlog = NLog.LogManager.GetCurrentClassLogger();
122+
Dictionary<string, object> dictionary = new Dictionary<string, object>();
123+
dictionary["clientid"] = 1;
124+
dictionary["color"] = "red";
125+
nlog.Debug("Test message", dictionary);
126+
```
110127

111128
Options
112129

@@ -123,36 +140,39 @@ PM> Install-Package StackifyLib.log4net
123140

124141
Note: Nuget packages are compiled against 2.0.0 (1.2.11) but any newer version will work with a valid assembly binding redirect. log4net 2.0.3 is actually 1.2.13 which makes the binding redirect look strange.
125142

126-
<dependentAssembly>
143+
```xml
144+
<dependentAssembly>
127145
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
128146
<bindingRedirect oldVersion="1.2.11.0-1.2.13.0" newVersion="1.2.13.0" />
129-
</dependentAssembly>
147+
</dependentAssembly>
148+
```
130149

131150
Sample config:
132-
133-
<log4net>
134-
<root>
135-
<level value="DEBUG" />
136-
<appender-ref ref="StackifyAppender" />
137-
</root>
138-
<appender name="StackifyAppender" type="StackifyLib.log4net.StackifyAppender, StackifyLib.log4net">
139-
<globalContextKeys>examplekey1,key2</globalContextKeys>
140-
<threadContextKeys></threadContextKeys>
141-
<logicalThreadContextKeys></logicalThreadContextKeys>
142-
143-
<callContextKeys></callContextKeys>
144-
145-
<!-- If logging a very high rate of messages, disable logging method names for performance -->
146-
<logMethodNames>true</logMethodNames>
147-
148-
<!-- Only log errors and fatals by using filters and setting levelMin and levelMax appropriately -->
149-
<!-- http://logging.apache.org/log4net/release/manual/configuration.html -->
150-
<filter type="log4net.Filter.LevelRangeFilter">
151-
<levelMin value="DEBUG" />
152-
<levelMax value="FATAL" />
153-
</filter>
154-
</appender>
155-
</log4net>
151+
```xml
152+
<log4net>
153+
<root>
154+
<level value="DEBUG" />
155+
<appender-ref ref="StackifyAppender" />
156+
</root>
157+
<appender name="StackifyAppender" type="StackifyLib.log4net.StackifyAppender, StackifyLib.log4net">
158+
<globalContextKeys>examplekey1,key2</globalContextKeys>
159+
<threadContextKeys></threadContextKeys>
160+
<logicalThreadContextKeys></logicalThreadContextKeys>
161+
162+
<callContextKeys></callContextKeys>
163+
164+
<!-- If logging a very high rate of messages, disable logging method names for performance -->
165+
<logMethodNames>true</logMethodNames>
166+
167+
<!-- Only log errors and fatals by using filters and setting levelMin and levelMax appropriately -->
168+
<!-- http://logging.apache.org/log4net/release/manual/configuration.html -->
169+
<filter type="log4net.Filter.LevelRangeFilter">
170+
<levelMin value="DEBUG" />
171+
<levelMax value="FATAL" />
172+
</filter>
173+
</appender>
174+
</log4net>
175+
```
156176

157177
Options
158178

@@ -165,14 +185,16 @@ Options
165185

166186
log4net does not internally have methods for logging a log message along with an object. Stackify's appenders work fine if you log an object directly or we have created some friendly extension methods to make it easy to log an object with your message at the same time.
167187

168-
using StackifyLib; //extension methods are here
169-
static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Program));
170-
Dictionary<string, object> dictionary = new Dictionary<string, object>();
171-
dictionary["clientid"] = 1;
172-
dictionary["name"] = "process name";
173-
logger.Debug("Starting some process for client 1"); //Normal basic log message works fine
174-
logger.Debug(dictionary); //This works fine and is indexed and searchable by Stackify
175-
logger.Debug("Starting some process for client 1", dictionary); //extension method
188+
```cshapr
189+
using StackifyLib; //extension methods are here
190+
static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Program));
191+
Dictionary<string, object> dictionary = new Dictionary<string, object>();
192+
dictionary["clientid"] = 1;
193+
dictionary["name"] = "process name";
194+
logger.Debug("Starting some process for client 1"); //Normal basic log message works fine
195+
logger.Debug(dictionary); //This works fine and is indexed and searchable by Stackify
196+
logger.Debug("Starting some process for client 1", dictionary); //extension method
197+
```
176198

177199
###log4net v1.2.10
178200

@@ -193,54 +215,58 @@ PM> Install-Package StackifyLib
193215

194216
If you use a custom logging framework or a framework not currently supported, you can easily send logs to Stackify with our core library and API like so:
195217

196-
StackifyLib.Logger.Queue("DEBUG", "My log message");
197-
StackifyLib.Logger.QueueException("Test exception", new ApplicationException("Sky is falling"));
198-
199-
StackifyLib.Logger.Shutdown(); //should be called before your app closes to flush the log queue
200-
201-
//More advanced example
202-
LogMsg msg = new LogMsg();
203-
msg.Ex = StackifyError.New(new ApplicationException("Exception goes here"));
204-
msg.AppDetails = new LogMsgGroup() {AppName = "My app", Env = "Prod", ServerName = Environment.MachineName};
205-
msg.data = StackifyLib.Utils.HelperFunctions.SerializeDebugData(new { color= "red"}, true);
206-
msg.Msg = "My log message";
207-
msg.Level = "ERROR";
208-
StackifyLib.Logger.QueueLogObject(msg);
218+
```csharp
219+
StackifyLib.Logger.Queue("DEBUG", "My log message");
220+
StackifyLib.Logger.QueueException("Test exception", new ApplicationException("Sky is falling"));
221+
222+
StackifyLib.Logger.Shutdown(); //should be called before your app closes to flush the log queue
223+
224+
//More advanced example
225+
LogMsg msg = new LogMsg();
226+
msg.Ex = StackifyError.New(new ApplicationException("Exception goes here"));
227+
msg.AppDetails = new LogMsgGroup() {AppName = "My app", Env = "Prod", ServerName = Environment.MachineName};
228+
msg.data = StackifyLib.Utils.HelperFunctions.SerializeDebugData(new { color= "red"}, true);
229+
msg.Msg = "My log message";
230+
msg.Level = "ERROR";
231+
StackifyLib.Logger.QueueLogObject(msg);
232+
```
209233

210234
*Make sure you call StackifyLib.Logger.Shutdown() before your app ends to flush the queue*
211235

212236
###Configuring with Azure service definitions
213237

214238
StackifyLib reads the license key, app name, and environment settings from normal web.config appSettings. If you would prefer to store the settings in an [azure cloud deployment cscfg](http://msdn.microsoft.com/en-us/library/azure/hh369931.aspx#NameValue), then you can create a little code to read the settings from there and set the StackifyLib settings in code like this in some similar way.
215239

216-
public class MvcApplication : System.Web.HttpApplication
217-
{
218-
public override void Init()
219-
{
220-
base.Init();
221-
StackifyLib.Logger.GlobalApiKey = GetConfig("Stackify.ApiKey");
222-
StackifyLib.Logger.GlobalEnvironment = GetConfig("Stackify.Environment");
223-
StackifyLib.Logger.GlobalAppName = "My App Name"; //probably no reason to make this one configurable
224-
}
225-
}
226-
227-
public static string GetConfig(string configName)
228-
{
229-
//Doing an if here in case it's being used outside of azure emulator.
230-
//Do this however works best for your project
231-
try
232-
{
233-
if (RoleEnvironment.IsAvailable)
234-
{
235-
return RoleEnvironment.GetConfigurationSettingValue(configName);
236-
}
237-
else
238-
{
239-
return ConfigurationManager.AppSettings[configName];
240-
}
241-
}
242-
catch (Exception ex)
243-
{
244-
}
245-
return null;
246-
}
240+
```csharp
241+
public class MvcApplication : System.Web.HttpApplication
242+
{
243+
public override void Init()
244+
{
245+
base.Init();
246+
StackifyLib.Logger.GlobalApiKey = GetConfig("Stackify.ApiKey");
247+
StackifyLib.Logger.GlobalEnvironment = GetConfig("Stackify.Environment");
248+
StackifyLib.Logger.GlobalAppName = "My App Name"; //probably no reason to make this one configurable
249+
}
250+
}
251+
252+
public static string GetConfig(string configName)
253+
{
254+
//Doing an if here in case it's being used outside of azure emulator.
255+
//Do this however works best for your project
256+
try
257+
{
258+
if (RoleEnvironment.IsAvailable)
259+
{
260+
return RoleEnvironment.GetConfigurationSettingValue(configName);
261+
}
262+
else
263+
{
264+
return ConfigurationManager.AppSettings[configName];
265+
}
266+
}
267+
catch (Exception ex)
268+
{
269+
}
270+
return null;
271+
}
272+
```

Src/StackifyLib/StackifyLib.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<AssemblyTitle>Stackify API</AssemblyTitle>
5-
<VersionPrefix>2.0.0-beta1</VersionPrefix>
5+
<VersionPrefix>2.0.0</VersionPrefix>
66
<TargetFrameworks>netstandard1.3;net40;net45;net451</TargetFrameworks>
77
<AssemblyName>StackifyLib</AssemblyName>
88
<PackageId>StackifyLib</PackageId>

appveyor.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: '{build}'
2+
os: Visual Studio 2017
3+
4+
pull_requests:
5+
do_not_increment_build_number: true
6+
7+
branches:
8+
only:
9+
- develop
10+
11+
nuget:
12+
disable_publish_on_pr: true
13+
14+
init:
15+
- SET PATH=C:\Program Files\PostgreSQL\9.6\bin\;%PATH%
16+
17+
build_script:
18+
- ps: .\Build.ps1
19+
20+
test: off
21+
22+
artifacts:
23+
- path: .\**\artifacts\**\*.nupkg
24+
name: NuGet
25+
26+
deploy:
27+
- provider: NuGet
28+
server: https://www.myget.org/F/stackify-private/api/v2
29+
api_key:
30+
secure: Txfu3efySdQMNgs/NF4N3dXvnMckOkQXNRL0ILka6BwQc3mUX4Isn8/r17N1J7l6
31+
skip_symbols: true
32+
on:
33+
branch: develop

build.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
2+
$revision = "{0:D4}" -f [convert]::ToInt32($revision, 10)
3+
4+
dotnet restore .\Src
5+
6+
dotnet build .\Src\StackifyLib -c Release
7+
dotnet build .\Src\StackifyLib.AspNetCore -c Release
8+
dotnet build .\Src\StackifyLib.CoreLogger -c Release
9+
#dotnet build .\Src\StackifyLib.ELMAH -c Release
10+
dotnet build .\Src\StackifyLib.log4net -c Release
11+
#dotnet build .\Src\StackifyLib.log4net.Sitecore -c Release
12+
#dotnet build .\Src\StackifyLib.log4net.Tests -c Release
13+
#dotnet build .\Src\StackifyLib.log4net.v1_2_10 -c Release
14+
#dotnet build .\Src\StackifyLib.nlog -c Release
15+
#dotnet build .\Src\StackifyLib.NoWeb -c Release
16+
dotnet build .\Src\StackifyLib.StackifyTraceListener -c Release
17+
18+
Write-Output "APPVEYOR_REPO_TAG: $env:APPVEYOR_REPO_TAG"
19+
Write-Output "VERSION-SUFFIX: alpha1-$revision"
20+
21+
If($env:APPVEYOR_REPO_TAG -eq $true) {
22+
Write-Output "RUNNING dotnet pack .\Src\StackifyLib -c Release -o .\artifacts "
23+
dotnet pack .\Src\StackifyLib -c Release -o .\artifacts
24+
}
25+
Else {
26+
Write-Output "RUNNING dotnet pack .\Src\StackifyLib -c Release -o .\artifacts --version-suffix=alpha1-$revision"
27+
dotnet pack .\Src\StackifyLib -c Release -o .\artifacts --version-suffix=beta1-$revision
28+
}

0 commit comments

Comments
 (0)