Skip to content

Commit 9b11af4

Browse files
roei sabagroei sabag
authored andcommitted
update YAML; update README.md
1 parent 6d9afff commit 9b11af4

File tree

4 files changed

+99
-2
lines changed

4 files changed

+99
-2
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
1-
# gravity-abstraction-logging
1+
# Gravity Abstraction Logging
22
Gravity API, logging abstraction. Allows to create any type of logging output using standard conventions.
3+
4+
# Quick Start (using the existing ```TraceLogger```)
5+
```csharp
6+
/*
7+
* if you want the log files to be save in the current directory, do not set "inDirectory" argument.
8+
*/
9+
10+
var logger = new TraceLogger(applicationName: "myApplication", loggerName: "DataClass", inDirectory: @"C:\Logs");
11+
logger.Debug(message: "This is a debug message");
12+
```
13+
14+
# Implement Your Own Message Handling
15+
```csharp
16+
/*
17+
* You must inherit Logger class.
18+
*/
19+
20+
public class HttpLogger : Logger
21+
{
22+
private readonly string baseAddress;
23+
private readonly string applicationName;
24+
private static readonly HttpClient client = new HttpClient();
25+
26+
// Will be used to pass values into base class.
27+
public HttpLogger(string applicationName, string loggerName)
28+
: this(applicationName, loggerName, baseAddress: "http://localhost:5000/")
29+
{ }
30+
31+
// Custom constructor to take some HTTP Context.
32+
public HttpLogger(string applicationName, string loggerName, string baseAddress)
33+
: base(applicationName, loggerName)
34+
{
35+
this.baseAddress = baseAddress;
36+
this.applicationName = applicationName;
37+
client.BaseAddress = new Uri(baseAddress);
38+
}
39+
40+
// Creates a child logger with the same application name.
41+
public override ILogger CreateChildLogger(string loggerName)
42+
{
43+
return new HttpLogger(applicationName, loggerName, baseAddress);
44+
}
45+
46+
// Override the message parsing and sending.
47+
// At this point the logMessage is already populated and you can change it before sending.
48+
public override void OnExecutor(string level, IDictionary<string, object> logMessage)
49+
{
50+
// setup
51+
var requestBody = JsonConvert.SerializeObject(logMessage);
52+
var content = new StringContent(content: requestBody, Encoding.UTF8, mediaType: "application/json");
53+
54+
// some message manipulation
55+
logMessage["EndPoint"] = $"{baseAddress}/logging";
56+
logMessage["LogType"] = nameof(HttpLogger);
57+
58+
// send
59+
client.PostAsync("/loggingServe", content).GetAwaiter().GetResult();
60+
}
61+
}
62+
63+
/*
64+
* if you want the log files to be sent to "http://localhost:5000", do not set "baseAddress" argument.
65+
*/
66+
67+
var logger = new HttpLogger(applicationName: "myApplication", loggerName: "DataClass", baseAddress: @"http://loggingserver/");
68+
logger.Debug(message: "This is a debug message");
69+
```

azure-pipelines-csharp.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,29 @@ steps:
6262
command: 'push'
6363
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
6464
nuGetFeedType: 'external'
65-
publishFeedCredentials: 'nuget.org'
65+
publishFeedCredentials: 'nuget.org'
66+
67+
- task: PowerShell@2
68+
displayName: 'parse build version for GitHub tag'
69+
inputs:
70+
targetType: 'inline'
71+
script: |
72+
# setup
73+
[regex]$pattern = '(\d+.?)+'
74+
$version = $pattern.Matches('$(Build.BuildNumber)') | foreach-object {$_.Value}
75+
# set value
76+
Write-Host "##vso[task.setvariable variable=buildVersion]$version"
77+
78+
- task: GitHubRelease@1
79+
displayName: 'create GitHub tag'
80+
inputs:
81+
gitHubConnection: 'GitHub connection - Gravity API'
82+
repositoryName: 'gravity-api/gravity-abstraction-logging'
83+
action: 'create'
84+
target: '$(Build.SourceVersion)'
85+
tagSource: 'userSpecifiedTag'
86+
tag: 'v$(buildVersion)'
87+
title: 'Production v$(buildVersion)'
88+
releaseNotesSource: 'inline'
89+
changeLogCompareToRelease: 'lastFullRelease'
90+
changeLogType: 'commitBased'

src/csharp/Gravity.Abstraction.Logging/Gravity.Abstraction.Logging.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
99
ProjectSection(SolutionItems) = preProject
1010
..\..\..\azure-pipelines-csharp.yml = ..\..\..\azure-pipelines-csharp.yml
1111
..\..\..\azure-settings.runsettings = ..\..\..\azure-settings.runsettings
12+
..\..\..\README.md = ..\..\..\README.md
1213
EndProjectSection
1314
EndProject
1415
Global

src/csharp/Gravity.Abstraction.Logging/Gravity.Abstraction.Logging/Gravity.Abstraction.Logging.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@
1414
<NeutralLanguage>en-US</NeutralLanguage>
1515
</PropertyGroup>
1616

17+
<ItemGroup>
18+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
19+
</ItemGroup>
20+
1721
</Project>

0 commit comments

Comments
 (0)